diff --git a/.gitattributes b/.gitattributes index 138d01e2..222e4c5e 100644 --- a/.gitattributes +++ b/.gitattributes @@ -3,3 +3,7 @@ phpunit.xml export-ignore *.md export-ignore /tests export-ignore +/easy-ci.php export-ignore +/ecs.php export-ignore +/phpstan.neon export-ignore +/rector.php export-ignore \ No newline at end of file diff --git a/.github/workflows/auto_closer.yaml b/.github/workflows/auto_closer.yaml deleted file mode 100644 index de9fca80..00000000 --- a/.github/workflows/auto_closer.yaml +++ /dev/null @@ -1,23 +0,0 @@ -name: Auto Closer PR - -on: - pull_request_target: - types: [opened] - -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - # Optional. Post a issue comment just before closing a pull request. - comment: | - Hi, thank you for your contribution. - - Unfortunately, this repository is read-only. It's a split from our main monorepo repository. - - We'd like to kindly ask you to move the contribution there - https://github.com/symplify/symplify. - - We'll check it, review it and give you feed back right way. - - Thank you. diff --git a/.github/workflows/code_analysis.yaml b/.github/workflows/code_analysis.yaml new file mode 100644 index 00000000..55c4b3b9 --- /dev/null +++ b/.github/workflows/code_analysis.yaml @@ -0,0 +1,65 @@ +name: Code Analysis + +on: + pull_request: null + push: + branches: + - main + +env: + # see https://github.com/composer/composer/issues/9368#issuecomment-718112361 + COMPOSER_ROOT_VERSION: "dev-main" + +jobs: + code_analysis: + strategy: + fail-fast: false + matrix: + actions: + - + name: 'PHPStan' + run: composer phpstan --ansi + + - + name: 'Composer Validate' + run: composer validate --ansi + + - + name: 'Rector' + run: composer rector --ansi + + - + name: 'Coding Standard' + run: composer fix-cs --ansi + + - + name: 'Tests' + run: vendor/bin/phpunit + + - + name: 'PHP Linter' + run: vendor/bin/parallel-lint src tests + + - + name: 'Check Commented Code' + run: vendor/bin/easy-ci check-commented-code src tests --ansi + + - + name: 'Check Active Classes' + run: vendor/bin/easy-ci check-active-class src --ansi + + name: ${{ matrix.actions.name }} + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + # see https://github.com/shivammathur/setup-php + - uses: shivammathur/setup-php@v2 + with: + php-version: 8.1 + coverage: none + + # composer install cache - https://github.com/ramsey/composer-install + - uses: "ramsey/composer-install@v2" + + - run: ${{ matrix.actions.run }} diff --git a/.gitignore b/.gitignore index dfd6caa4..897bee40 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /vendor -composer.lock \ No newline at end of file +composer.lock +/.phpunit.result.cache \ No newline at end of file diff --git a/composer.json b/composer.json index 18ecd530..7547a5e8 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,16 @@ "symplify/package-builder": "^11.2" }, "require-dev": { - "phpunit/phpunit": "^9.5.26" + "php-parallel-lint/php-parallel-lint": "^1.3", + "phpstan/extension-installer": "^1.2", + "phpunit/phpunit": "^9.5.26", + "rector/rector": "^0.15.10", + "symplify/easy-ci": "^11.1", + "symplify/easy-coding-standard": "^11.1", + "symplify/package-builder": "^11.2", + "symplify/phpstan-rules": "11.2.3.72", + "symplify/symplify-kernel": "^11.2", + "tomasvotruba/unused-public": "^0.0.34" }, "autoload": { "psr-4": { @@ -31,22 +40,20 @@ ] } }, - "conflict": { - "symplify/phpstan-rules": "<11.1.24", - "symplify/easy-testing": "<11.1.25", - "symplify/rule-doc-generator-contracts": "<11.1.25", - "symplify/php-config-printer": "<11.1.25", - "symplify/autowire-array-parameter": "<11.1.25", - "symplify/rule-doc-generator": "<11.1.25", - "symplify/symfony-static-dumper": "<11.1.25", - "symplify/symplify-kernel": "<11.1.25", - "symplify/config-transformer": "<11.1.24", - "symplify/coding-standard": "<11.1.24", - "symplify/easy-parallel": "<11.1.25", - "symplify/smart-file-system": "<11.1.25", - "symplify/easy-ci": "<11.1.24", - "symplify/monorepo-builder": "<11.1.24" + "scripts": { + "check-cs": "vendor/bin/ecs check --ansi", + "fix-cs": "vendor/bin/ecs check --fix --ansi", + "phpstan": "vendor/bin/phpstan analyse --ansi --error-format symplify", + "rector": "vendor/bin/rector process --dry-run --ansi" }, "minimum-stability": "dev", - "prefer-stable": true + "prefer-stable": true, + "config": { + "sort-packages": true, + "platform-check": false, + "allow-plugins": { + "cweagans/composer-patches": true, + "phpstan/extension-installer": true + } + } } diff --git a/easy-ci.php b/easy-ci.php new file mode 100644 index 00000000..da45afe6 --- /dev/null +++ b/easy-ci.php @@ -0,0 +1,16 @@ +typesToSkip([ + NativeFunctionDynamicFunctionReturnTypeExtension::class, + ContainerGetReturnTypeExtension::class, + SplFileInfoTolerantReturnTypeExtension::class, + ]); +}; diff --git a/ecs.php b/ecs.php new file mode 100644 index 00000000..bb42212e --- /dev/null +++ b/ecs.php @@ -0,0 +1,21 @@ +paths([ + __DIR__ . '/ecs.php', + __DIR__ . '/rector.php', + __DIR__ . '/easy-ci.php', + __DIR__ . '/src', + __DIR__ . '/tests', + ]); + + $ecsConfig->sets([ + SetList::COMMON, + SetList::PSR_12, + ]); +}; diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 00000000..a84137f1 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,27 @@ +includes: + - config/config.neon + +parameters: + level: 8 + + paths: + - src + - tests + + excludePaths: + - '*/tests/**/Source/*' + - '*/tests/**/Fixture/*' + - '*/tests/**/data/*' + + unused_public: + methods: true + properties: true + constants: true + + ignoreErrors: + - '#Calling PHPStan\\Testing\\ErrorFormatterTestCase\:\:(getOutputContent|getOutput|getAnalysisResult)|\(\) is not covered by backward compatibility promise\. The method might change in a minor PHPStan version#' + - '#Extending PHPStan\\Testing\\ErrorFormatterTestCase is not covered by backward compatibility promise\. The class might change in a minor PHPStan version#' + + - + path: src/ErrorFormatter/SymplifyErrorFormatter.php + message: '#Cannot call method writeLineFormatted\(\) on PHPStan\\Command\\Output\|null#' diff --git a/rector.php b/rector.php new file mode 100644 index 00000000..8156100a --- /dev/null +++ b/rector.php @@ -0,0 +1,34 @@ +sets([ + SetList::CODE_QUALITY, + SetList::DEAD_CODE, + LevelSetList::UP_TO_PHP_81, + SetList::CODING_STYLE, + SetList::TYPE_DECLARATION, + SetList::NAMING, + SetList::PRIVATIZATION, + SetList::EARLY_RETURN, + PHPUnitSetList::PHPUNIT_CODE_QUALITY, + ]); + + $rectorConfig->paths([ + __DIR__ . '/src', + __DIR__ . '/tests', + ]); + + $rectorConfig->importNames(); + + $rectorConfig->skip([ + '*/Source/*', + '*/Fixture/*', + ]); +}; diff --git a/src/ErrorFormatter/SymplifyErrorFormatter.php b/src/ErrorFormatter/SymplifyErrorFormatter.php index c8874d97..3fe08631 100644 --- a/src/ErrorFormatter/SymplifyErrorFormatter.php +++ b/src/ErrorFormatter/SymplifyErrorFormatter.php @@ -35,7 +35,7 @@ final class SymplifyErrorFormatter implements ErrorFormatter private ?Output $output = null; public function __construct( - private Terminal $terminal + private readonly Terminal $terminal ) { } diff --git a/src/TypeExtension/MethodCall/ContainerGetReturnTypeExtension.php b/src/TypeExtension/MethodCall/ContainerGetReturnTypeExtension.php index a290e23d..91be7d41 100644 --- a/src/TypeExtension/MethodCall/ContainerGetReturnTypeExtension.php +++ b/src/TypeExtension/MethodCall/ContainerGetReturnTypeExtension.php @@ -20,7 +20,7 @@ final class ContainerGetReturnTypeExtension implements DynamicMethodReturnTypeExtension { public function __construct( - private ClassConstFetchReturnTypeResolver $classConstFetchReturnTypeResolver + private readonly ClassConstFetchReturnTypeResolver $classConstFetchReturnTypeResolver ) { } diff --git a/tests/TypeExtension/MethodCall/ContainerGetReturnTypeExtension/Source/ExternalService.php b/tests/TypeExtension/MethodCall/ContainerGetReturnTypeExtension/Source/ExternalService.php index 8ca54b88..4053d927 100644 --- a/tests/TypeExtension/MethodCall/ContainerGetReturnTypeExtension/Source/ExternalService.php +++ b/tests/TypeExtension/MethodCall/ContainerGetReturnTypeExtension/Source/ExternalService.php @@ -6,5 +6,4 @@ final class ExternalService { - } diff --git a/tests/TypeExtension/MethodCall/ContainerGetReturnTypeExtension/data/fixture.php b/tests/TypeExtension/MethodCall/ContainerGetReturnTypeExtension/data/fixture.php index 64e053a0..b1a8d4b5 100644 --- a/tests/TypeExtension/MethodCall/ContainerGetReturnTypeExtension/data/fixture.php +++ b/tests/TypeExtension/MethodCall/ContainerGetReturnTypeExtension/data/fixture.php @@ -6,7 +6,7 @@ use Symplify\PHPStanExtensions\Tests\TypeExtension\MethodCall\ContainerGetReturnTypeExtension\Source\ExternalService; use function PHPStan\Testing\assertType; -class SomeClass +final class SomeClass { public function run(ContainerInterface $container): void { diff --git a/tests/TypeExtension/MethodCall/SplFileInfoTolerantReturnTypeExtension/data/fixture.php b/tests/TypeExtension/MethodCall/SplFileInfoTolerantReturnTypeExtension/data/fixture.php index b61b401f..0106c030 100644 --- a/tests/TypeExtension/MethodCall/SplFileInfoTolerantReturnTypeExtension/data/fixture.php +++ b/tests/TypeExtension/MethodCall/SplFileInfoTolerantReturnTypeExtension/data/fixture.php @@ -5,7 +5,7 @@ use Symfony\Component\Finder\SplFileInfo; use function PHPStan\Testing\assertType; -class SomeClass +final class SomeClass { public function run(SplFileInfo $splFileInfo): void {