From 1bad89e488a3159dd9536945d34f4a5fd887ee1d Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Fri, 18 Oct 2024 11:50:25 +0200 Subject: [PATCH 1/2] update composer dependnecy analyser --- .github/workflows/code_analysis.yaml | 3 +++ composer-dependency-analyser.php | 15 +++++++++++++++ composer.json | 3 ++- .../directory-with-php/parameters.php | 2 +- 4 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 composer-dependency-analyser.php diff --git a/.github/workflows/code_analysis.yaml b/.github/workflows/code_analysis.yaml index d9552f8b217..0a3bdf32e16 100644 --- a/.github/workflows/code_analysis.yaml +++ b/.github/workflows/code_analysis.yaml @@ -36,6 +36,9 @@ jobs: name: 'Check Active Classes' run: vendor/bin/class-leak check bin src --ansi --skip-type="\Symplify\PhpConfigPrinter\Contract\NodeVisitor\PrePrintNodeVisitorInterface" + - + name: "Composer Dependency Analyser" + run: vendor/bin/composer-dependency-analyser name: ${{ matrix.actions.name }} runs-on: ubuntu-latest diff --git a/composer-dependency-analyser.php b/composer-dependency-analyser.php new file mode 100644 index 00000000000..c4129bd67ff --- /dev/null +++ b/composer-dependency-analyser.php @@ -0,0 +1,15 @@ +ignoreErrorsOnPackage('symfony/expression-language', [ErrorType::UNUSED_DEPENDENCY]) + + // test fixtures + ->addPathToExclude(__DIR__ . '/tests/Converter/ConfigFormatConverter/YamlToPhp/Source'); diff --git a/composer.json b/composer.json index 5f45129c734..3a8450814e3 100644 --- a/composer.json +++ b/composer.json @@ -8,6 +8,7 @@ "require": { "php": ">=8.2", "nette/utils": "^3.2", + "nikic/php-parser": "^4.19", "sebastian/diff": "^5.0", "symfony/config": "^6.4", "symfony/console": "^6.4", @@ -21,12 +22,12 @@ }, "require-dev": { "cweagans/composer-patches": "^1.7", - "icanhazstring/composer-unused": "0.8.7", "php-parallel-lint/php-parallel-lint": "^1.3", "phpstan/extension-installer": "^1.3", "phpstan/phpstan": "^1.10", "phpunit/phpunit": "^10.5", "rector/rector": "^0.19", + "shipmonk/composer-dependency-analyser": "^1.7", "symplify/easy-coding-standard": "^12.1", "symplify/phpstan-extensions": "^11.4", "symplify/vendor-patches": "^11.3", diff --git a/tests/Converter/ConfigFormatConverter/YamlToPhp/Fixture/skip-imported-php/directory-with-php/parameters.php b/tests/Converter/ConfigFormatConverter/YamlToPhp/Fixture/skip-imported-php/directory-with-php/parameters.php index 00d7066d24d..4cc3ec4a8db 100644 --- a/tests/Converter/ConfigFormatConverter/YamlToPhp/Fixture/skip-imported-php/directory-with-php/parameters.php +++ b/tests/Converter/ConfigFormatConverter/YamlToPhp/Fixture/skip-imported-php/directory-with-php/parameters.php @@ -2,7 +2,7 @@ declare(strict_types=1); -use Prefixed\Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; +use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; return static function (ContainerConfigurator $containerConfigurator): void { $parameters = $containerConfigurator->parameters(); From dac17ffd4e727f3bc24788a4d1d1ca47467e874d Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Fri, 18 Oct 2024 11:56:42 +0200 Subject: [PATCH 2/2] cleanup unused elements --- composer.json | 13 +++++----- phpstan.neon | 5 ++++ src/ConfigLoader.php | 5 ++-- src/Converter/ConfigFormatConverter.php | 5 ++-- src/Reflection/PrivatesAccessor.php | 9 ------- .../ContainerBuilderAndFileContent.php | 26 ------------------- tests/Helper/FixtureFinder.php | 1 + tests/Helper/FixtureSplitter.php | 3 +++ tests/Helper/FixtureUpdater.php | 3 +++ .../InputFileInfoAndExpectedFileInfo.php | 13 +++------- 10 files changed, 26 insertions(+), 57 deletions(-) delete mode 100644 src/ValueObject/ContainerBuilderAndFileContent.php diff --git a/composer.json b/composer.json index 3a8450814e3..b9abb362327 100644 --- a/composer.json +++ b/composer.json @@ -22,16 +22,17 @@ }, "require-dev": { "cweagans/composer-patches": "^1.7", - "php-parallel-lint/php-parallel-lint": "^1.3", - "phpstan/extension-installer": "^1.3", - "phpstan/phpstan": "^1.10", + "php-parallel-lint/php-parallel-lint": "^1.4", + "phpstan/extension-installer": "^1.4", + "phpstan/phpstan": "^1.12", "phpunit/phpunit": "^10.5", - "rector/rector": "^0.19", + "rector/rector": "^1.2", "shipmonk/composer-dependency-analyser": "^1.7", - "symplify/easy-coding-standard": "^12.1", + "symplify/easy-coding-standard": "^12.3", "symplify/phpstan-extensions": "^11.4", "symplify/vendor-patches": "^11.3", - "tomasvotruba/class-leak": "^0.2.6" + "tomasvotruba/class-leak": "^1.0", + "tomasvotruba/unused-public": "^1.0" }, "autoload": { "psr-4": { diff --git a/phpstan.neon b/phpstan.neon index ff40832de50..d69db5710df 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -11,6 +11,11 @@ parameters: - '*/Source/*' - '*/Fixture/*' + unused_public: + constants: true + properties: true + methods: true + ignoreErrors: - message: '#Parameter \#1 \$commandName of method Symfony\\Component\\Console\\Application\:\:setDefaultCommand\(\) expects string, string\|null given#' diff --git a/src/ConfigLoader.php b/src/ConfigLoader.php index adca633f1e2..7e25288353d 100644 --- a/src/ConfigLoader.php +++ b/src/ConfigLoader.php @@ -21,7 +21,6 @@ use Symplify\ConfigTransformer\DependencyInjection\Loader\SkippingPhpFileLoader; use Symplify\ConfigTransformer\Enum\Format; use Symplify\ConfigTransformer\Exception\NotImplementedYetException; -use Symplify\ConfigTransformer\ValueObject\ContainerBuilderAndFileContent; final class ConfigLoader { @@ -44,7 +43,7 @@ public function __construct( public function createAndLoadContainerBuilderFromFileInfo( SplFileInfo $fileInfo, - ): ContainerBuilderAndFileContent { + ): string { $containerBuilder = new ContainerBuilder(); $delegatingLoader = $this->createLoaderBySuffix($containerBuilder, $fileInfo->getExtension()); @@ -85,7 +84,7 @@ public function createAndLoadContainerBuilderFromFileInfo( // usefull in gradual upgrade of configs } - return new ContainerBuilderAndFileContent($containerBuilder, $content); + return $content; } private function createLoaderBySuffix(ContainerBuilder $containerBuilder, string $suffix): DelegatingLoader diff --git a/src/Converter/ConfigFormatConverter.php b/src/Converter/ConfigFormatConverter.php index 97baf432103..ab5c550a55a 100644 --- a/src/Converter/ConfigFormatConverter.php +++ b/src/Converter/ConfigFormatConverter.php @@ -23,13 +23,12 @@ public function convert(SplFileInfo $fileInfo): string { $this->currentFilePathProvider->setFilePath($fileInfo->getRealPath()); - $containerBuilderAndFileContent = $this->configLoader->createAndLoadContainerBuilderFromFileInfo( + $dumpedContainerContent = $this->configLoader->createAndLoadContainerBuilderFromFileInfo( $fileInfo ); if (in_array($fileInfo->getExtension(), [Format::YAML, Format::YML], true)) { - $dumpedYaml = $containerBuilderAndFileContent->getFileContent(); - return $this->yamlToPhpConverter->convert($dumpedYaml, $fileInfo->getRealPath()); + return $this->yamlToPhpConverter->convert($dumpedContainerContent, $fileInfo->getRealPath()); } $message = sprintf('Suffix "%s" is not support yet', $fileInfo->getExtension()); diff --git a/src/Reflection/PrivatesAccessor.php b/src/Reflection/PrivatesAccessor.php index 49a9287d904..6da44f7d945 100644 --- a/src/Reflection/PrivatesAccessor.php +++ b/src/Reflection/PrivatesAccessor.php @@ -8,15 +8,6 @@ final class PrivatesAccessor { - // read private property - public static function readPrivateProperty(object $object, string $propertyName): mixed - { - $reflectionProperty = new ReflectionProperty($object, $propertyName); - $reflectionProperty->setAccessible(true); - - return $reflectionProperty->getValue($object); - } - // write private property public static function writePrivateProperty(object $object, string $propertyName, mixed $value): void { diff --git a/src/ValueObject/ContainerBuilderAndFileContent.php b/src/ValueObject/ContainerBuilderAndFileContent.php deleted file mode 100644 index 6e90c5f2102..00000000000 --- a/src/ValueObject/ContainerBuilderAndFileContent.php +++ /dev/null @@ -1,26 +0,0 @@ -containerBuilder; - } - - public function getFileContent(): string - { - return $this->fileContent; - } -} diff --git a/tests/Helper/FixtureFinder.php b/tests/Helper/FixtureFinder.php index 172080a3f96..19d56a091a0 100644 --- a/tests/Helper/FixtureFinder.php +++ b/tests/Helper/FixtureFinder.php @@ -11,6 +11,7 @@ final class FixtureFinder { /** + * @api used in tests * @return Iterator> */ public static function yieldDirectory(string $directory, string $suffix = '*.php.inc'): Iterator diff --git a/tests/Helper/FixtureSplitter.php b/tests/Helper/FixtureSplitter.php index 00e22eb8658..a98be153d35 100644 --- a/tests/Helper/FixtureSplitter.php +++ b/tests/Helper/FixtureSplitter.php @@ -10,6 +10,9 @@ use Symplify\ConfigTransformer\Tests\Helper\ValueObject\InputAndExpected; use Symplify\ConfigTransformer\Tests\Helper\ValueObject\InputFileInfoAndExpectedFileInfo; +/** + * @api used in tests + */ final class FixtureSplitter { /** diff --git a/tests/Helper/FixtureUpdater.php b/tests/Helper/FixtureUpdater.php index c47a2c7580d..61853a329cc 100644 --- a/tests/Helper/FixtureUpdater.php +++ b/tests/Helper/FixtureUpdater.php @@ -7,6 +7,9 @@ use Nette\Utils\FileSystem; use Symfony\Component\Finder\SplFileInfo; +/** + * @api used in tests + */ final class FixtureUpdater { public static function updateFixtureContent( diff --git a/tests/Helper/ValueObject/InputFileInfoAndExpectedFileInfo.php b/tests/Helper/ValueObject/InputFileInfoAndExpectedFileInfo.php index 43d2e8ae007..8dee0ae270b 100644 --- a/tests/Helper/ValueObject/InputFileInfoAndExpectedFileInfo.php +++ b/tests/Helper/ValueObject/InputFileInfoAndExpectedFileInfo.php @@ -6,6 +6,9 @@ use Symfony\Component\Finder\SplFileInfo; +/** + * @api used in tests + */ final class InputFileInfoAndExpectedFileInfo { public function __construct( @@ -19,18 +22,8 @@ public function getInputFileInfo(): SplFileInfo return $this->inputFileInfo; } - public function getExpectedFileInfo(): SplFileInfo - { - return $this->expectedFileInfo; - } - public function getExpectedFileContent(): string { return $this->expectedFileInfo->getContents(); } - - public function getExpectedFileInfoRealPath(): string - { - return $this->expectedFileInfo->getRealPath(); - } }