From 53ee52cfe3b6c28e22d24a828e5426899897af8b Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Fri, 3 Feb 2023 22:31:07 +0700 Subject: [PATCH 01/10] Move symplify/packages/package-builder source here --- composer.json | 4 +--- src/Console/Formatter/ColorConsoleDiffFormatter.php | 2 +- src/Console/Output/ConsoleDiffer.php | 4 ++-- src/Console/Style/SymfonyStyleFactory.php | 2 +- .../CompilerPass/AutowireInterfacesCompilerPass.php | 2 +- .../FileLoader/ParameterMergingPhpFileLoader.php | 2 +- src/Diff/Output/CompleteUnifiedDiffOutputBuilderFactory.php | 2 +- src/Strings/StringFormatConverter.php | 4 +++- 8 files changed, 11 insertions(+), 11 deletions(-) diff --git a/composer.json b/composer.json index 56f19c8..ff7e5eb 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ "symfony/finder": "^6.2" }, "require-dev": { - "symplify/symplify-kernel": "^11.2", + "symplify/symplify-kernel": "^11.1", "phpunit/phpunit": "^9.5.26" }, "autoload": { @@ -34,11 +34,9 @@ "symplify/phpstan-rules": "<11.1.24", "symplify/rule-doc-generator-contracts": "<11.1.25", "symplify/php-config-printer": "<11.1.25", - "symplify/autowire-array-parameter": "<11.1.25", "symplify/phpstan-extensions": "<11.1.25", "symplify/rule-doc-generator": "<11.1.25", "symplify/smart-file-system": "<11.1.25", - "symplify/symfony-static-dumper": "<11.1.25", "symplify/config-transformer": "<11.1.24", "symplify/coding-standard": "<11.1.24", "symplify/easy-parallel": "<11.1.25", diff --git a/src/Console/Formatter/ColorConsoleDiffFormatter.php b/src/Console/Formatter/ColorConsoleDiffFormatter.php index 80783a3..71997e5 100644 --- a/src/Console/Formatter/ColorConsoleDiffFormatter.php +++ b/src/Console/Formatter/ColorConsoleDiffFormatter.php @@ -39,7 +39,7 @@ final class ColorConsoleDiffFormatter */ private const NEWLINES_REGEX = "#\n\r|\n#"; - private string $template; + private readonly string $template; public function __construct() { diff --git a/src/Console/Output/ConsoleDiffer.php b/src/Console/Output/ConsoleDiffer.php index 6821ae9..4c4736f 100644 --- a/src/Console/Output/ConsoleDiffer.php +++ b/src/Console/Output/ConsoleDiffer.php @@ -13,8 +13,8 @@ final class ConsoleDiffer { public function __construct( - private Differ $differ, - private ColorConsoleDiffFormatter $colorConsoleDiffFormatter + private readonly Differ $differ, + private readonly ColorConsoleDiffFormatter $colorConsoleDiffFormatter ) { } diff --git a/src/Console/Style/SymfonyStyleFactory.php b/src/Console/Style/SymfonyStyleFactory.php index 57d4fc1..5587042 100644 --- a/src/Console/Style/SymfonyStyleFactory.php +++ b/src/Console/Style/SymfonyStyleFactory.php @@ -16,7 +16,7 @@ */ final class SymfonyStyleFactory { - private PrivatesCaller $privatesCaller; + private readonly PrivatesCaller $privatesCaller; public function __construct() { diff --git a/src/DependencyInjection/CompilerPass/AutowireInterfacesCompilerPass.php b/src/DependencyInjection/CompilerPass/AutowireInterfacesCompilerPass.php index 79d606d..46cb7b1 100644 --- a/src/DependencyInjection/CompilerPass/AutowireInterfacesCompilerPass.php +++ b/src/DependencyInjection/CompilerPass/AutowireInterfacesCompilerPass.php @@ -13,7 +13,7 @@ final class AutowireInterfacesCompilerPass implements CompilerPassInterface * @param string[] $typesToAutowire */ public function __construct( - private array $typesToAutowire + private readonly array $typesToAutowire ) { } diff --git a/src/DependencyInjection/FileLoader/ParameterMergingPhpFileLoader.php b/src/DependencyInjection/FileLoader/ParameterMergingPhpFileLoader.php index c2115ba..61885ad 100644 --- a/src/DependencyInjection/FileLoader/ParameterMergingPhpFileLoader.php +++ b/src/DependencyInjection/FileLoader/ParameterMergingPhpFileLoader.php @@ -20,7 +20,7 @@ */ final class ParameterMergingPhpFileLoader extends PhpFileLoader { - private ParametersMerger $parametersMerger; + private readonly ParametersMerger $parametersMerger; public function __construct(ContainerBuilder $containerBuilder, FileLocatorInterface $fileLocator) { diff --git a/src/Diff/Output/CompleteUnifiedDiffOutputBuilderFactory.php b/src/Diff/Output/CompleteUnifiedDiffOutputBuilderFactory.php index 49a8d1b..1933543 100644 --- a/src/Diff/Output/CompleteUnifiedDiffOutputBuilderFactory.php +++ b/src/Diff/Output/CompleteUnifiedDiffOutputBuilderFactory.php @@ -14,7 +14,7 @@ final class CompleteUnifiedDiffOutputBuilderFactory { public function __construct( - private PrivatesAccessor $privatesAccessor + private readonly PrivatesAccessor $privatesAccessor ) { } diff --git a/src/Strings/StringFormatConverter.php b/src/Strings/StringFormatConverter.php index f74e762..d330644 100644 --- a/src/Strings/StringFormatConverter.php +++ b/src/Strings/StringFormatConverter.php @@ -66,7 +66,9 @@ private function camelCaseToGlue(string $input, string $glue): string $parts = []; foreach ($matches as $match) { - $parts[] = $match[0] === strtoupper($match[0]) ? strtolower($match[0]) : lcfirst($match[0]); + $parts[] = $match[0] === strtoupper((string) $match[0]) ? strtolower($match[0]) : lcfirst( + (string) $match[0] + ); } return implode($glue, $parts); From 5c249b11f3217603bbc8f4317d7102637e0391e9 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Fri, 3 Feb 2023 22:32:50 +0700 Subject: [PATCH 02/10] add code analyzsis workflow --- .github/workflows/auto_closer.yaml | 23 ---------- .github/workflows/code_analysis.yaml | 65 ++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 23 deletions(-) delete mode 100644 .github/workflows/auto_closer.yaml create mode 100644 .github/workflows/code_analysis.yaml diff --git a/.github/workflows/auto_closer.yaml b/.github/workflows/auto_closer.yaml deleted file mode 100644 index de9fca8..0000000 --- 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 0000000..55c4b3b --- /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 }} From 683c90e0870576996695990500f06f45b60ba118 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sun, 5 Feb 2023 20:03:04 +0700 Subject: [PATCH 03/10] config --- .gitattributes | 6 +++++- easy-ci.php | 16 ++++++++++++++++ ecs.php | 21 +++++++++++++++++++++ phpstan.neon | 27 +++++++++++++++++++++++++++ rector.php | 34 ++++++++++++++++++++++++++++++++++ 5 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 easy-ci.php create mode 100644 ecs.php create mode 100644 phpstan.neon create mode 100644 rector.php diff --git a/.gitattributes b/.gitattributes index 2ee71f1..3d02405 100644 --- a/.gitattributes +++ b/.gitattributes @@ -4,4 +4,8 @@ LICENSE export-ignore phpunit.xml export-ignore *.md export-ignore -docs/ export-ignore \ No newline at end of file +docs/ export-ignore +/easy-ci.php export-ignore +/ecs.php export-ignore +/phpstan.neon export-ignore +/rector.php export-ignore diff --git a/easy-ci.php b/easy-ci.php new file mode 100644 index 0000000..da45afe --- /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 0000000..bb42212 --- /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 0000000..a84137f --- /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 0000000..8156100 --- /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/*', + ]); +}; From a15404e4c65dd14888921a58f00fbefcbecfde6f Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sun, 5 Feb 2023 20:04:32 +0700 Subject: [PATCH 04/10] update --- composer.json | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/composer.json b/composer.json index ff7e5eb..c2e0d0f 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,14 @@ }, "require-dev": { "symplify/symplify-kernel": "^11.1", - "phpunit/phpunit": "^9.5.26" + "phpunit/phpunit": "^9.5.26", + "php-parallel-lint/php-parallel-lint": "^1.3", + "phpstan/extension-installer": "^1.2", + "rector/rector": "^0.15.10", + "symplify/easy-ci": "^11.1", + "symplify/easy-coding-standard": "^11.1", + "symplify/phpstan-rules": "11.2.3.72", + "tomasvotruba/unused-public": "^0.0.34" }, "autoload": { "psr-4": { @@ -30,21 +37,20 @@ "dev-main": "11.2-dev" } }, - "conflict": { - "symplify/phpstan-rules": "<11.1.24", - "symplify/rule-doc-generator-contracts": "<11.1.25", - "symplify/php-config-printer": "<11.1.25", - "symplify/phpstan-extensions": "<11.1.25", - "symplify/rule-doc-generator": "<11.1.25", - "symplify/smart-file-system": "<11.1.25", - "symplify/config-transformer": "<11.1.24", - "symplify/coding-standard": "<11.1.24", - "symplify/easy-parallel": "<11.1.25", - "symplify/easy-testing": "<11.1.25", - "symplify/symplify-kernel": "<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 + } + } } From 7593f0a41a2b272583c5611203bfd33d56820cdd Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sun, 5 Feb 2023 20:06:02 +0700 Subject: [PATCH 05/10] fix easy-ci --- easy-ci.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/easy-ci.php b/easy-ci.php index da45afe..60bf8b1 100644 --- a/easy-ci.php +++ b/easy-ci.php @@ -2,15 +2,11 @@ declare(strict_types=1); +use Symplify\PackageBuilder\DependencyInjection\CompilerPass\AutowireInterfacesCompilerPass; use Symplify\EasyCI\Config\EasyCIConfig; -use Symplify\PHPStanExtensions\TypeExtension\FuncCall\NativeFunctionDynamicFunctionReturnTypeExtension; -use Symplify\PHPStanExtensions\TypeExtension\MethodCall\ContainerGetReturnTypeExtension; -use Symplify\PHPStanExtensions\TypeExtension\MethodCall\SplFileInfoTolerantReturnTypeExtension; return static function (EasyCIConfig $easyCIConfig): void { $easyCIConfig->typesToSkip([ - NativeFunctionDynamicFunctionReturnTypeExtension::class, - ContainerGetReturnTypeExtension::class, - SplFileInfoTolerantReturnTypeExtension::class, + AutowireInterfacesCompilerPass::class, ]); }; From 3d268b4cd2c2537fe470a6a663dc0804fd9f4c1d Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sun, 5 Feb 2023 20:06:50 +0700 Subject: [PATCH 06/10] fix phpstan --- phpstan.neon | 3 --- 1 file changed, 3 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index a84137f..7136143 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,6 +1,3 @@ -includes: - - config/config.neon - parameters: level: 8 From c582bb0be4383885e377c9d498787343f99f48c5 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sun, 5 Feb 2023 20:08:05 +0700 Subject: [PATCH 07/10] phpstan --- composer.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index c2e0d0f..0933bcd 100644 --- a/composer.json +++ b/composer.json @@ -12,14 +12,15 @@ "symfony/finder": "^6.2" }, "require-dev": { - "symplify/symplify-kernel": "^11.1", - "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/phpstan-extensions": "^11.1", "symplify/phpstan-rules": "11.2.3.72", + "symplify/symplify-kernel": "^11.1", "tomasvotruba/unused-public": "^0.0.34" }, "autoload": { From e9b78991fc7b927cb7a804e1466484e35493b186 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sun, 5 Feb 2023 20:08:19 +0700 Subject: [PATCH 08/10] phpstan --- phpstan.neon | 6 ------ 1 file changed, 6 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index 7136143..b1483ed 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -16,9 +16,3 @@ parameters: 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#' From 51bde7c4138f1559dfd38540c0ebdb7b8f82d225 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sun, 5 Feb 2023 20:13:14 +0700 Subject: [PATCH 09/10] generate baseline --- phpstan.neon | 3 +++ 1 file changed, 3 insertions(+) diff --git a/phpstan.neon b/phpstan.neon index b1483ed..d74d40e 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,3 +1,6 @@ +includes: + - phpstan-baseline.neon + parameters: level: 8 From 8481ba7310e94ff1f7b7cfadf285f8808e3f46d6 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sun, 5 Feb 2023 20:13:19 +0700 Subject: [PATCH 10/10] generate baseline --- phpstan-baseline.neon | 46 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 phpstan-baseline.neon diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon new file mode 100644 index 0000000..f652bbc --- /dev/null +++ b/phpstan-baseline.neon @@ -0,0 +1,46 @@ +parameters: + ignoreErrors: + - + message: "#^Parameter \\#1 \\$path of function dirname expects string, string\\|false given\\.$#" + count: 1 + path: src/Composer/VendorDirProvider.php + + - + message: "#^Call to an undefined method Symfony\\\\Component\\\\DependencyInjection\\\\ContainerInterface\\:\\:getParameterBag\\(\\)\\.$#" + count: 1 + path: src/Parameter/ParameterProvider.php + + - + message: "#^Parameter \\#1 \\$objectOrClass of class ReflectionClass constructor expects class\\-string\\\\|T of object, string given\\.$#" + count: 1 + path: src/Reflection/ClassLikeExistenceChecker.php + + - + message: "#^Parameter \\#1 \\$objectOrClass of class ReflectionClass constructor expects class\\-string\\\\|T of object, string given\\.$#" + count: 2 + path: src/Reflection/PrivatesCaller.php + + - + message: "#^Call to method setConfigs\\(\\) on an unknown class Symplify\\\\PackageBuilder\\\\Contract\\\\HttpKernel\\\\ExtraConfigAwareKernelInterface\\.$#" + count: 1 + path: src/Testing/AbstractKernelTestCase.php + + - + message: "#^Class Symplify\\\\PackageBuilder\\\\Contract\\\\HttpKernel\\\\ExtraConfigAwareKernelInterface not found\\.$#" + count: 2 + path: src/Testing/AbstractKernelTestCase.php + + - + message: "#^PHPDoc tag @var for variable \\$kernel contains unknown class Symplify\\\\PackageBuilder\\\\Contract\\\\HttpKernel\\\\ExtraConfigAwareKernelInterface\\.$#" + count: 1 + path: src/Testing/AbstractKernelTestCase.php + + - + message: "#^Parameter \\#1 \\$kernel of method Symplify\\\\PackageBuilder\\\\Testing\\\\AbstractKernelTestCase\\:\\:bootAndReturnKernel\\(\\) expects Symfony\\\\Component\\\\HttpKernel\\\\KernelInterface, Symplify\\\\PackageBuilder\\\\Contract\\\\HttpKernel\\\\ExtraConfigAwareKernelInterface given\\.$#" + count: 1 + path: src/Testing/AbstractKernelTestCase.php + + - + message: "#^Static property Symplify\\\\PackageBuilder\\\\Testing\\\\AbstractKernelTestCase\\:\\:\\$container \\(Symfony\\\\Component\\\\DependencyInjection\\\\ContainerInterface\\|null\\) does not accept Psr\\\\Container\\\\ContainerInterface\\.$#" + count: 2 + path: src/Testing/AbstractKernelTestCase.php