From 5c85296c1f359eabf0b70942dc2f2fbee57a728c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20K=C3=B6rner?= Date: Fri, 18 Nov 2022 09:00:33 +0100 Subject: [PATCH] added phpstan config file, raised phpstan level to 2 --- .github/workflows/ci.yml | 2 +- README.md | 2 +- composer.json | 3 ++- phpstan.neon | 19 ++++++++++++++++++ src/Asset/EntrypointsJsonLookup.php | 8 +++++--- src/Collection/EntryCollection.php | 7 ++++--- src/DependencyInjection/Configuration.php | 20 +++---------------- .../ReplaceDynamicScriptTagsListener.php | 2 +- src/Helper/ArrayHelper.php | 3 +-- 9 files changed, 37 insertions(+), 29 deletions(-) create mode 100644 phpstan.neon diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 16565ca..0877bd7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -74,4 +74,4 @@ jobs: run: composer install --no-interaction - name: PHPStan - run: vendor/bin/phpstan analyse src/ tests/ --level=1 \ No newline at end of file + run: vendor/bin/phpstan analyse -c phpstan.neon \ No newline at end of file diff --git a/README.md b/README.md index fe75fc2..368e98a 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![Total Downloads](https://img.shields.io/packagist/dt/heimrichhannot/contao-encore-bundle.svg)](https://packagist.org/packages/heimrichhannot/contao-encore-bundle) ![CI](https://github.com/heimrichhannot/contao-encore-bundle/workflows/CI/badge.svg) [![Coverage Status](https://coveralls.io/repos/github/heimrichhannot/contao-encore-bundle/badge.svg?branch=master)](https://coveralls.io/github/heimrichhannot/contao-encore-bundle?branch=master) -![](https://img.shields.io/badge/PHPStan-level%201-brightgreen.svg?style=flat) +![](https://img.shields.io/badge/PHPStan-level%202-brightgreen.svg?style=flat) Use the power and simplicity of symfony webpack encore in contao. This bundle let you decide on layout and page level, which encore entries should be loaded. If you want more, you can prepare your bundles define their own encore entries, so never need to manually add or remove encore entries again. diff --git a/composer.json b/composer.json index 7491ce4..8d7bc3e 100644 --- a/composer.json +++ b/composer.json @@ -45,7 +45,8 @@ "php-coveralls/php-coveralls": "^2.0", "symfony/phpunit-bridge": "^3.2 || ^4.0 || ^5.0 || ^6.0", "heimrichhannot/contao-test-utilities-bundle": "^0.1.4", - "phpstan/phpstan": "^1.8" + "phpstan/phpstan": "^1.8", + "phpstan/phpstan-symfony": "^1.2" }, "autoload": { "psr-4": { diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..327363c --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,19 @@ +parameters: + level: 2 + paths: + - src + - tests + universalObjectCratesClasses: + - Contao\LayoutModel + - Contao\Model + - Contao\Template + - PHPUnit\Framework\MockObject\MockObject + ignoreErrors: + - message: '#^Call to an undefined method PHPUnit\\Framework\\MockObject\\MockObject\:\:setName\(\)\.$#' + path: tests/EventListener/Contao/ParseTemplateListenerTest.php + - message: '#^Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\NodeDefinition\:\:getChildNodeDefinitions\(\)\.$#' + path: tests/DependencyInjection/ConfigurationTest.php + - message: '#^Call to an undefined method Symfony\\Component\\Config\\Definition\\NodeInterface\:\:getChildren\(\)\.$#' + path: tests/DependencyInjection/ConfigurationTest.php +includes: + - vendor/phpstan/phpstan-symfony/extension.neon \ No newline at end of file diff --git a/src/Asset/EntrypointsJsonLookup.php b/src/Asset/EntrypointsJsonLookup.php index 21d3257..8853ef3 100644 --- a/src/Asset/EntrypointsJsonLookup.php +++ b/src/Asset/EntrypointsJsonLookup.php @@ -10,6 +10,7 @@ use Contao\LayoutModel; use Psr\Cache\CacheItemPoolInterface; +use Psr\Cache\InvalidArgumentException; /** * @deprecated Use EntryCollection instead @@ -39,9 +40,10 @@ public function __construct(array $bundleConfig, CacheItemPoolInterface $cache = } /** - * @param array $entrypointJsonFiles entrypoint json files - * @param array $bundleConfigEntries Entries defined by encore bundle config - * @param string|null $babelPolyfillEntryName entry name of babel polyfill + * @param array $entrypointJsonFiles entrypoint json files + * @param array $bundleConfigEntries Entries defined by encore bundle config + * + * @throws InvalidArgumentException */ public function mergeEntries(array $entrypointJsonFiles, array $bundleConfigEntries, LayoutModel $layout = null): array { diff --git a/src/Collection/EntryCollection.php b/src/Collection/EntryCollection.php index 7750be4..2290e89 100644 --- a/src/Collection/EntryCollection.php +++ b/src/Collection/EntryCollection.php @@ -47,9 +47,10 @@ public function getEntries(): array } /** - * @param array $entrypointJsonFiles entrypoint json files - * @param array $bundleConfigEntries Entries defined by encore bundle config - * @param string|null $babelPolyfillEntryName entry name of babel polyfill + * @param array $entrypointJsonFiles entrypoint json files + * @param array $bundleConfigEntries Entries defined by encore bundle config + * + * @throws NoEntrypointsException */ private function mergeEntries(array $entrypointJsonFiles, array $bundleConfigEntries, LayoutModel $layout = null): array { diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 5781a81..eb01b2a 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -1,7 +1,7 @@ root('huh_encore'); - } else { - $rootNode = $treeBuilder->getRootNode(); - } - - $rootNode + $treeBuilder->getRootNode() ->children() ->booleanNode('use_contao_template_variables') ->defaultFalse() @@ -110,14 +103,7 @@ public function getConfigTreeBuilder() public function addLegacyNode() { $treeBuilder = new TreeBuilder('encore'); - - // Keep compatibility with symfony/config < 4.2 - if (!method_exists($treeBuilder, 'getRootNode')) { - $node = $treeBuilder->root('encore'); - } else { - $node = $treeBuilder->getRootNode(); - } - + $node = $treeBuilder->getRootNode(); $node ->addDefaultsIfNotSet() ->setDeprecated('Configs within encore key are deprecated and will be removed in next major version.') diff --git a/src/EventListener/Contao/ReplaceDynamicScriptTagsListener.php b/src/EventListener/Contao/ReplaceDynamicScriptTagsListener.php index ca62d5e..ee89ff1 100644 --- a/src/EventListener/Contao/ReplaceDynamicScriptTagsListener.php +++ b/src/EventListener/Contao/ReplaceDynamicScriptTagsListener.php @@ -66,10 +66,10 @@ public function __invoke(string $buffer): string $pageModel->loadDetails(); - /** @var LayoutModel|null $layout */ if (!($layout = $this->contaoFramework->getAdapter(LayoutModel::class)->findByPk(($pageModel->layoutId ?? $pageModel->layout)))) { return $buffer; } + /* @var LayoutModel|null $layout */ if (!isset($this->bundleConfig['use_contao_template_variables']) || true !== $this->bundleConfig['use_contao_template_variables']) { $buffer = $this->replaceEncoreTags($buffer, $pageModel, $layout); diff --git a/src/Helper/ArrayHelper.php b/src/Helper/ArrayHelper.php index d220822..5eacbdc 100644 --- a/src/Helper/ArrayHelper.php +++ b/src/Helper/ArrayHelper.php @@ -1,7 +1,7 @@