From 1f6fb610ddd5461df9c3524736f531f12f1b0c29 Mon Sep 17 00:00:00 2001 From: Thomas Date: Fri, 24 Feb 2023 09:51:13 +0100 Subject: [PATCH] Check Util folder with phpstan (#63) * add phpstan config and deps * fix phpstan errors, add phpstan to ci pipeline --- .github/workflows/ci.yml | 17 +++++++++++++++++ composer.json | 4 +++- phpstan.neon | 19 +++++++++++++++++++ src/Util/Model/ModelUtil.php | 4 ++-- src/Util/Request/RequestUtil.php | 6 +++--- src/Util/Request/UrlUtil.php | 5 +++-- src/Util/Type/StringUtil.php | 4 +--- src/Util/Ui/AccordionUtil.php | 8 +++++++- 8 files changed, 55 insertions(+), 12 deletions(-) create mode 100644 phpstan.neon diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8a0f5fd9..3a5c7cdb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -63,3 +63,20 @@ jobs: run: | composer global require php-coveralls/php-coveralls php-coveralls --coverage_clover=build/logs/clover.xml -v + + phpstan: + runs-on: ubuntu-latest + steps: + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: 8.0 + + - name: Checkout + uses: actions/checkout@v2 + + - name: Install the dependencies + run: composer install --no-interaction + + - name: PHPStan + run: vendor/bin/phpstan analyse -c phpstan.neon \ No newline at end of file diff --git a/composer.json b/composer.json index 23daa201..2211a473 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,9 @@ "heimrichhannot/contao-test-utilities-bundle": "^0.1", "phpunit/phpunit": "^8.0 || ^9.0", "php-coveralls/php-coveralls": "^2.0", - "symfony/phpunit-bridge": "^3.2 || ^4.0 || ^5.0" + "symfony/phpunit-bridge": "^3.2 || ^4.0 || ^5.0", + "phpstan/phpstan": "^1.10", + "phpstan/phpstan-symfony": "^1.2" }, "conflict": { "heimrichhannot/contao-encore-bundle": "<1.5" diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 00000000..e717ba4d --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,19 @@ +parameters: + level: 2 + paths: + - src/Util + - tests/Util +# 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/Util/Model/ModelUtil.php b/src/Util/Model/ModelUtil.php index 5854162d..e2c87fbe 100644 --- a/src/Util/Model/ModelUtil.php +++ b/src/Util/Model/ModelUtil.php @@ -1,7 +1,7 @@ framework->getAdapter(Model::class)->getClassFromTable($table))) { return null; } diff --git a/src/Util/Request/RequestUtil.php b/src/Util/Request/RequestUtil.php index 1332e41f..0d58b203 100644 --- a/src/Util/Request/RequestUtil.php +++ b/src/Util/Request/RequestUtil.php @@ -1,7 +1,7 @@ false, ], $options); + /** @var array|false $urlParts */ $urlParts = parse_url($url); if (false === $urlParts) { diff --git a/src/Util/Type/StringUtil.php b/src/Util/Type/StringUtil.php index e26464df..137f69c3 100644 --- a/src/Util/Type/StringUtil.php +++ b/src/Util/Type/StringUtil.php @@ -1,7 +1,7 @@ contaoFramework = $contaoFramework;