Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/code_samples.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ jobs:
name: Validate code samples
runs-on: "ubuntu-22.04"
strategy:
fail-fast: false
matrix:
php:
- "8.4" # Upper supported version
Expand Down Expand Up @@ -47,6 +48,12 @@ jobs:

- name: Run PHPStan analysis
run: composer phpstan

- if: matrix.php == '8.4' # ibexa/rector supports PHP 8.3 and higher
name: Run Rector check
run: |
composer require --dev ibexa/rector:~4.6.x-dev
composer check-rector

code-samples-inclusion-check:
name: Check code samples inclusion
Expand Down
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,23 @@
composer phpstan
```

## Downgrading code samples with Rector

Code samples must be compatible with PHP 7.4.
Rector is used to check and downgrade PHP 8.x syntax and functions to PHP 7.4-compatible equivalents.

Check notice on line 66 in README.md

View workflow job for this annotation

GitHub Actions / vale

[vale] README.md#L66

[Ibexa.ByUsingStartOfLine] Prefer 'by using' or 'with' to plain 'using'.
Raw output
{"message": "[Ibexa.ByUsingStartOfLine] Prefer 'by using' or 'with' to plain 'using'.", "location": {"path": "README.md", "range": {"start": {"line": 66, "column": 4}}}, "severity": "INFO"}
To check which files need downgrading (dry-run, no changes applied):
```bash
composer require --dev ibexa/rector:~4.6.x-dev

Check warning on line 69 in README.md

View workflow job for this annotation

GitHub Actions / vale

[vale] README.md#L69

[Ibexa.FirstPersonPronouns] Do not use first person pronouns unless specifically referring to our company.
Raw output
{"message": "[Ibexa.FirstPersonPronouns] Do not use first person pronouns unless specifically referring to our company.", "location": {"path": "README.md", "range": {"start": {"line": 69, "column": 46}}}, "severity": "WARNING"}
composer check-rector
```

Check notice on line 71 in README.md

View workflow job for this annotation

GitHub Actions / vale

[vale] README.md#L71

[Ibexa.ArticlesInHeadings] Avoid articles in headings.
Raw output
{"message": "[Ibexa.ArticlesInHeadings] Avoid articles in headings.", "location": {"path": "README.md", "range": {"start": {"line": 71, "column": 12}}}, "severity": "INFO"}

To refactor the code samples, run:

``` bash
vendor/bin/rector
```

## Where to View

https://doc.ibexa.co
2 changes: 1 addition & 1 deletion code_samples/api/commerce/src/Command/PaymentCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function __construct(
UserService $userService,
PaymentServiceInterface $paymentService,
OrderServiceInterface $orderService,
PaymentMethodServiceInterface $paymentMethodService,
PaymentMethodServiceInterface $paymentMethodService
) {
$this->paymentService = $paymentService;
$this->permissionResolver = $permissionResolver;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class MySuggestionEventSubscriber implements EventSubscriberInterface, LoggerAwa
private ProductServiceInterface $productService;

public function __construct(
ProductServiceInterface $productService,
ProductServiceInterface $productService
) {
$this->productService = $productService;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected function doHandle(StepInterface $step)
continue;
}

if (str_contains($field->value, 'Company Name')) {
if (strpos($field->value, 'Company Name') !== false) {
$newValue = str_replace('Company Name', $step->getReplacement(), $field->value);
$struct->setField($field->fieldDefIdentifier, new Value($newValue));
}
Expand Down
12 changes: 11 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
"url": "https://updates.ibexa.co"
}
],
"require": {
"php": "^7.4 || ^8.0"
},
"require-dev": {
"ibexa/automated-translation": "4.6.x-dev",
"ibexa/code-style": "^1.0",
Expand Down Expand Up @@ -82,7 +85,14 @@
"scripts": {
"fix-cs": "php-cs-fixer fix --config=.php-cs-fixer.php -v --show-progress=dots",
"check-cs": "@fix-cs --dry-run",
"phpstan": "phpstan analyse"
"phpstan": "phpstan analyse",
"check-rector": "rector process --dry-run --ansi"
},
"suggest": {
"ibexa/rector": "Add Rector to check for code refactoring opportunities"
},
"scripts-descriptions": {
"check-rector": "Check for code refactoring opportunities"
},
"config": {
"allow-plugins": false
Expand Down
27 changes: 27 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

use Rector\Config\RectorConfig;
use Ibexa\Contracts\Rector\Sets\IbexaSetList;
use Rector\Symfony\DowngradeSymfony70\Rector\Class_\DowngradeSymfonyCommandAttributeRector;
use Rector\DowngradePhp82\Rector\FuncCall\DowngradeIteratorCountToArrayRector;

return RectorConfig::configure()
->withPaths([
__DIR__ . '/code_samples',
])
->withSkip([
DowngradeIteratorCountToArrayRector::class,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This rule didn't work and resulted in an infinite loop in one of the code samples.

])
->withSets([
IbexaSetList::IBEXA_46->value,
])
->withDowngradeSets(php74: true)
->withRules([
DowngradeSymfonyCommandAttributeRector::class,
]);
Loading