diff --git a/.github/workflows/code_analysis.yaml b/.github/workflows/code_analysis.yaml index 7c56860..45c9000 100644 --- a/.github/workflows/code_analysis.yaml +++ b/.github/workflows/code_analysis.yaml @@ -32,6 +32,10 @@ jobs: name: 'Tests' run: vendor/bin/phpunit + - + name: 'Dependency Analysis' + run: vendor/bin/composer-dependency-analyser + - name: 'Check Active Classes' run: vendor/bin/class-leak check src --ansi --skip-type="\Symplify\PhpConfigPrinter\Contract\Converter\ServiceOptionsKeyYamlToPhpFactoryInterface" --skip-type="\Symplify\PhpConfigPrinter\Contract\RoutingCaseConverterInterface" --skip-type="\Symplify\PhpConfigPrinter\Contract\CaseConverterInterface" diff --git a/.gitignore b/.gitignore index 382f83c..412b580 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,6 @@ composer.lock .phpunit.cache + +# symfony kernel cache dir +/var diff --git a/README.md b/README.md index 822d665..a901825 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![Downloads total](https://img.shields.io/packagist/dt/symplify/php-config-printer.svg?style=flat-square)](https://packagist.org/packages/symplify/php-config-printer/stats) -Print Symfony services array with configuration to to plain PHP file format thanks to this simple php-parser wrapper +Print Symfony services array with configuration to to plain PHP file format using [nikic/php-parser](https://github.com/nikic/PHP-Parser) ## Install diff --git a/composer-dependency-analyser.php b/composer-dependency-analyser.php new file mode 100644 index 0000000..92eaf90 --- /dev/null +++ b/composer-dependency-analyser.php @@ -0,0 +1,16 @@ +ignoreErrorsOnPackage('myclabs/php-enum', [ErrorType::DEV_DEPENDENCY_IN_PROD]); + +return $configuration; diff --git a/composer.json b/composer.json index 2662b55..c9364a5 100644 --- a/composer.json +++ b/composer.json @@ -4,18 +4,24 @@ "license": "MIT", "require": { "php": ">=8.2", - "nette/utils": "^3.2", - "nikic/php-parser": "^5.3", - "symfony/yaml": "^6.4" + "ext-ctype": "*", + "nette/utils": "^4.0", + "nikic/php-parser": "^5.5", + "symfony/dependency-injection": "^6.4|^7.3", + "symfony/service-contracts": "^3.6", + "symfony/yaml": "^6.4", + "webmozart/assert": "^1.11" }, "require-dev": { + "symfony/config": "^6.4|^7.3", + "symfony/http-kernel": "^6.4|^7.3", "myclabs/php-enum": "^1.8", + "phpecs/phpecs": "^2.1", "phpstan/extension-installer": "^1.4", "phpstan/phpstan": "^2.1", - "phpunit/phpunit": "^10.5", - "rector/rector": "^2.0", - "phpecs/phpecs": "^2.0", - "symplify/easy-testing": "^11.1", + "phpunit/phpunit": "^11.5", + "rector/rector": "^2.1", + "shipmonk/composer-dependency-analyser": "^1.8", "symplify/phpstan-extensions": "^12.0", "tomasvotruba/class-leak": "^2.0" }, diff --git a/config/config.php b/config/config.php index 82560f2..3015710 100644 --- a/config/config.php +++ b/config/config.php @@ -37,7 +37,6 @@ __DIR__ . '/../src/RoutingCaseConverter' )->tag(RoutingCaseConverterInterface::class); - $services->load( 'Symplify\\PhpConfigPrinter\\ServiceOptionConverter\\', __DIR__ . '/../src/ServiceOptionConverter' diff --git a/ecs.php b/ecs.php index a727014..00d9e79 100644 --- a/ecs.php +++ b/ecs.php @@ -6,6 +6,7 @@ return ECSConfig::configure() ->withPaths([ + __DIR__ . '/config', __DIR__ . '/src', __DIR__ . '/tests', ]) diff --git a/phpstan.neon b/phpstan.neon index 9cb986b..c92138e 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -22,3 +22,8 @@ parameters: # unclear what to do - '#Parameter \#1 \$items of class PhpParser\\Node\\Expr\\Array_ constructor expects array, array given#' + + # runs also on older PHP versions, like 7.4+ + - + message: '#Right side of && is always true#' + path: src/NodeFactory/ArgsNodeFactory.php diff --git a/rector.php b/rector.php index ccd4af5..63524d9 100644 --- a/rector.php +++ b/rector.php @@ -24,5 +24,4 @@ // old value is needed \Rector\Php81\Rector\MethodCall\MyCLabsMethodCallToEnumConstRector::class, - ]); diff --git a/src/Naming/ReferenceFunctionNameResolver.php b/src/Naming/ReferenceFunctionNameResolver.php index 38bb2d5..dd5a17b 100644 --- a/src/Naming/ReferenceFunctionNameResolver.php +++ b/src/Naming/ReferenceFunctionNameResolver.php @@ -17,6 +17,13 @@ final class ReferenceFunctionNameResolver */ public static function resolve(): string { + $symfonyFunctionsFile = getcwd() . '/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Loader/Configurator/ContainerConfigurator.php'; + + if (file_exists($symfonyFunctionsFile)) { + // this file must be included manually, as composer will only load it once function called + require_once $symfonyFunctionsFile; + } + if (function_exists(FunctionName::REF)) { return FunctionName::REF; } diff --git a/tests/AbstractTestCase.php b/tests/AbstractTestCase.php new file mode 100644 index 0000000..a7d3d47 --- /dev/null +++ b/tests/AbstractTestCase.php @@ -0,0 +1,36 @@ +boot(); + + $this->container = $testKernel->getContainer(); + } + + /** + * @template TType as object + * + * @param class-string $type + * @return TType + */ + public function getService(string $type): object + { + if (! $this->container->has($type)) { + throw new \RuntimeException(sprintf('Service "%s" not found in container.', $type)); + } + + return $this->container->get($type); + } +} diff --git a/tests/HttpKernel/PhpConfigPrinterKernel.php b/tests/HttpKernel/PhpConfigPrinterKernel.php deleted file mode 100644 index 5611721..0000000 --- a/tests/HttpKernel/PhpConfigPrinterKernel.php +++ /dev/null @@ -1,21 +0,0 @@ -create($configFiles); - } -} diff --git a/tests/HttpKernel/TestKernel.php b/tests/HttpKernel/TestKernel.php new file mode 100644 index 0000000..2597ef9 --- /dev/null +++ b/tests/HttpKernel/TestKernel.php @@ -0,0 +1,24 @@ +load(__DIR__ . '/../../config/config.php'); + } +} diff --git a/tests/Printer/SmartPhpConfigPrinter/SmartPhpConfigPrinterTest.php b/tests/Printer/SmartPhpConfigPrinter/SmartPhpConfigPrinterTest.php index d7343b1..5dee9b2 100644 --- a/tests/Printer/SmartPhpConfigPrinter/SmartPhpConfigPrinterTest.php +++ b/tests/Printer/SmartPhpConfigPrinter/SmartPhpConfigPrinterTest.php @@ -6,20 +6,20 @@ use Iterator; use PHPUnit\Framework\Attributes\DataProvider; -use Symplify\PackageBuilder\Testing\AbstractKernelTestCase; use Symplify\PhpConfigPrinter\Printer\SmartPhpConfigPrinter; -use Symplify\PhpConfigPrinter\Tests\HttpKernel\PhpConfigPrinterKernel; +use Symplify\PhpConfigPrinter\Tests\AbstractTestCase; use Symplify\PhpConfigPrinter\Tests\Printer\SmartPhpConfigPrinter\Source\ClassWithConstants; use Symplify\PhpConfigPrinter\Tests\Printer\SmartPhpConfigPrinter\Source\FirstClass; use Symplify\PhpConfigPrinter\Tests\Printer\SmartPhpConfigPrinter\Source\SecondClass; -final class SmartPhpConfigPrinterTest extends AbstractKernelTestCase +final class SmartPhpConfigPrinterTest extends AbstractTestCase { private SmartPhpConfigPrinter $smartPhpConfigPrinter; protected function setUp(): void { - $this->bootKernel(PhpConfigPrinterKernel::class); + parent::setUp(); + $this->smartPhpConfigPrinter = $this->getService(SmartPhpConfigPrinter::class); }