Skip to content

Commit

Permalink
Updated to use PHPStan and Rector 2.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexSkrypnyk committed Jan 7, 2025
1 parent d1efa7a commit cca66ff
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 88 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:

strategy:
matrix:
php-versions: ['8.1', '8.2', '8.3']
php-versions: ['8.2', '8.3', '8.4']

steps:
- name: Checkout code
Expand Down
13 changes: 7 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "drevops/behat-format-progress-fail",
"type": "library",
"description": "Behat output formatter to show progress as TAP and fails inline.",
"license": "GPL-2.0-or-later",
"type": "library",
"authors": [
{
"name": "Alex Skrypnyk",
Expand All @@ -22,11 +22,11 @@
"behat/mink": "^1.8",
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
"drevops/behat-phpserver": "^1",
"ergebnis/composer-normalize": "^2.45",
"escapestudios/symfony2-coding-standard": "^3",
"phpmd/phpmd": "^2.14",
"phpstan/phpstan": "^1.10",
"phpstan/phpstan": "^2",
"phpunit/phpunit": "^10.0",
"rector/rector": "^1.0.0",
"rector/rector": "^2",
"squizlabs/php_codesniffer": "^3",
"symfony/process": "^6 || ^7.0"
},
Expand All @@ -37,20 +37,21 @@
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
"dealerdirect/phpcodesniffer-composer-installer": true,
"ergebnis/composer-normalize": true
}
},
"scripts": {
"lint": [
"phpcs",
"phpmd --exclude vendor . text phpmd.xml",
"phpstan",
"rector --clear-cache --dry-run"
],
"lint-fix": [
"rector --clear-cache",
"phpcbf"
],
"reset": "rm -Rf vendor vendor-bin composer.lock",
"test": "vendor/bin/behat"
}
}
24 changes: 0 additions & 24 deletions phpmd.xml

This file was deleted.

78 changes: 37 additions & 41 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,53 +15,49 @@
use Rector\CodeQuality\Rector\ClassMethod\InlineArrayReturnAssignRector;
use Rector\CodeQuality\Rector\Empty_\SimplifyEmptyCheckOnEmptyArrayRector;
use Rector\CodingStyle\Rector\ClassMethod\NewlineBeforeNewAssignSetRector;
use Rector\CodingStyle\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector;
use Rector\CodingStyle\Rector\FuncCall\CountArrayToEmptyArrayComparisonRector;
use Rector\CodingStyle\Rector\PostInc\PostIncDecToPreIncDecRector;
use Rector\CodingStyle\Rector\Stmt\NewlineAfterStatementRector;
use Rector\Config\RectorConfig;
use Rector\DeadCode\Rector\If_\RemoveAlwaysTrueIfConditionRector;
use Rector\Set\ValueObject\SetList;
use Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__ . '/**',
]);

$rectorConfig->sets([
SetList::PHP_80,
SetList::PHP_81,
SetList::CODE_QUALITY,
SetList::CODING_STYLE,
SetList::DEAD_CODE,
SetList::INSTANCEOF,
SetList::TYPE_DECLARATION,
]);

$rectorConfig->skip([
// Rules added by Rector's rule sets.
ArraySpreadInsteadOfArrayMergeRector::class,
CountArrayToEmptyArrayComparisonRector::class,
DisallowedEmptyRuleFixerRector::class,
InlineArrayReturnAssignRector::class,
NewlineAfterStatementRector::class,
NewlineBeforeNewAssignSetRector::class,
PostIncDecToPreIncDecRector::class,
RemoveAlwaysTrueIfConditionRector::class,
SimplifyEmptyCheckOnEmptyArrayRector::class,
// Dependencies.
'*/vendor/*',
'*/node_modules/*',
// BehatCliContext.
'tests/behat/features/bootstrap/BehatCliContext.php',
]);

$rectorConfig->fileExtensions([
'php',
'inc',
]);

$rectorConfig->importNames(TRUE, FALSE);
$rectorConfig->importShortClasses(FALSE);
$rectorConfig->paths([
__DIR__ . '/**',
]);

$rectorConfig->sets([
SetList::PHP_80,
SetList::PHP_81,
SetList::CODE_QUALITY,
SetList::CODING_STYLE,
SetList::DEAD_CODE,
SetList::INSTANCEOF,
SetList::TYPE_DECLARATION,
]);

$rectorConfig->skip([
// Rules added by Rector's rule sets.
CountArrayToEmptyArrayComparisonRector::class,
DisallowedEmptyRuleFixerRector::class,
InlineArrayReturnAssignRector::class,
NewlineAfterStatementRector::class,
NewlineBeforeNewAssignSetRector::class,
RemoveAlwaysTrueIfConditionRector::class,
SimplifyEmptyCheckOnEmptyArrayRector::class,
// Dependencies.
'*/vendor/*',
'*/node_modules/*',
// BehatCliContext.
'tests/behat/features/bootstrap/BehatCliContext.php',
]);

$rectorConfig->fileExtensions([
'php',
'inc',
]);

$rectorConfig->importNames(TRUE, FALSE);
$rectorConfig->importShortClasses(FALSE);
};
8 changes: 5 additions & 3 deletions src/DrevOps/BehatFormatProgressFail/FormatExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,11 @@ public function configure(ArrayNodeDefinition $builder): void
*/
public function load(ContainerBuilder $container, array $config): void
{
$name = is_string($config['name']) ? $config['name'] : self::MOD_ID;

$definition = new Definition(
StepListener::class, [
new Reference('output.printer.'.$config['name']),
new Reference('output.printer.'.$name),
]
);
$container->setDefinition(self::ROOT_LISTENER_ID, $definition);
Expand All @@ -99,7 +101,7 @@ public function load(ContainerBuilder $container, array $config): void
]
);
$container->setDefinition(
'output.printer.'.$config['name'], $definition
'output.printer.'.$name, $definition
);

$definition = new Definition(
Expand Down Expand Up @@ -150,7 +152,7 @@ public function load(ContainerBuilder $container, array $config): void
OutputExtension::FORMATTER_TAG, ['priority' => 100]
);
$container->setDefinition(
OutputExtension::FORMATTER_TAG.'.'.$config['name'], $definition
OutputExtension::FORMATTER_TAG.'.'.$name, $definition
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,11 @@ protected function printFailure(StepResult $result, StepNode $step): string

return '';
}, $stepArguments);

$stepArguments = array_filter($stepArguments);

if (count($stepArguments) > 0) {
$output .= sprintf(sprintf(' {+%s}%%s{-%s}', $style, $style), implode(PHP_EOL, array_filter($stepArguments)));
$output .= sprintf(sprintf(' {+%s}%%s{-%s}', $style, $style), implode(PHP_EOL, $stepArguments));
$output .= PHP_EOL;
}

Expand Down
18 changes: 6 additions & 12 deletions tests/behat/features/format-progress-fail.feature
Original file line number Diff line number Diff line change
Expand Up @@ -155,26 +155,20 @@ Feature: behat-format-progress-fail
--- FeatureContextTest has missing steps. Define them with these snippets:
/**
* @Then /^do something undefined$/
*/
public function doSomethingUndefined()
#[Then('/^do something undefined$/')]
public function doSomethingUndefined(): void
{
throw new PendingException();
}
/**
* @Given /^pystring:$/
*/
public function pystring(PyStringNode $string)
#[Given('/^pystring:$/')]
public function pystring(PyStringNode $string): void
{
throw new PendingException();
}
/**
* @Given /^table:$/
*/
public function table(TableNode $table)
#[Given('/^table:$/')]
public function table(TableNode $table): void
{
throw new PendingException();
}
Expand Down

0 comments on commit cca66ff

Please sign in to comment.