Skip to content

Commit

Permalink
Check Util folder with phpstan (#63)
Browse files Browse the repository at this point in the history
* add phpstan config and deps

* fix phpstan errors, add phpstan to ci pipeline
  • Loading branch information
koertho committed Feb 24, 2023
1 parent c5d3d6a commit 1f6fb61
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 12 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
19 changes: 19 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions src/Util/Model/ModelUtil.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/*
* Copyright (c) 2022 Heimrich & Hannot GmbH
* Copyright (c) 2023 Heimrich & Hannot GmbH
*
* @license LGPL-3.0-or-later
*/
Expand Down Expand Up @@ -81,7 +81,7 @@ public function findModelInstancesBy(string $table, $columns, $values, array $op
];
$options = array_merge($defaults, $options);

/** @var string|null $modelClass */
/* @var string|null $modelClass */
if (!($modelClass = $this->framework->getAdapter(Model::class)->getClassFromTable($table))) {
return null;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Util/Request/RequestUtil.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/*
* Copyright (c) 2022 Heimrich & Hannot GmbH
* Copyright (c) 2023 Heimrich & Hannot GmbH
*
* @license LGPL-3.0-or-later
*/
Expand Down Expand Up @@ -42,7 +42,7 @@ public function __construct(ModelUtil $modelUtil, RequestStack $requestStack, ar
/**
* Return the current page model.
*
* @return PageModel|Model|null the current page model or null if no page context
* @return PageModel|null the current page model or null if no page context
*
* @See AbstractContentElementController::getPageModel()
*/
Expand Down Expand Up @@ -84,7 +84,7 @@ public function getCurrentPageModel(): ?PageModel
/**
* Return the root page of the current page.
*
* @return PageModel|Model|null the root page model or null if not exist
* @return PageModel|null the root page model or null if not exist
*/
public function getCurrentRootPageModel(PageModel $currentPage = null): ?PageModel
{
Expand Down
5 changes: 3 additions & 2 deletions src/Util/Request/UrlUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ public function addQueryStringParameterToUrl(string $parameter, string $url = ''
* Options:
* - removeLeadingSlash: (boolean) Remove leading slash from path
*
* @param string $url The url that should be made relative
* @param array{removeLeadingSlash: bool} $options Pass additional options
* @param string $url The url that should be made relative
* @param array $options Pass additional options
*
* @throws InvalidUrlException
*/
Expand All @@ -101,6 +101,7 @@ public function makeUrlRelative(string $url, array $options = []): string
'removeLeadingSlash' => false,
], $options);

/** @var array|false $urlParts */
$urlParts = parse_url($url);

if (false === $urlParts) {
Expand Down
4 changes: 1 addition & 3 deletions src/Util/Type/StringUtil.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/*
* Copyright (c) 2022 Heimrich & Hannot GmbH
* Copyright (c) 2023 Heimrich & Hannot GmbH
*
* @license LGPL-3.0-or-later
*/
Expand Down Expand Up @@ -235,8 +235,6 @@ public function pregReplaceLast(string $regExp, string $subject, string $replace

/**
* Convert an xml string to array.
*
* @return mixed
*/
public function convertXmlToArray(string $xmlData): ?array
{
Expand Down
8 changes: 7 additions & 1 deletion src/Util/Ui/AccordionUtil.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/*
* Copyright (c) 2022 Heimrich & Hannot GmbH
* Copyright (c) 2023 Heimrich & Hannot GmbH
*
* @license LGPL-3.0-or-later
*/
Expand All @@ -18,6 +18,12 @@ class AccordionUtil
*/
private $contaoFramework;

/** @var array */
private $accordionStartStopCache = [];

/** @var array */
private $accordionSingleCache;

public function __construct(ContaoFramework $contaoFramework)
{
$this->contaoFramework = $contaoFramework;
Expand Down

0 comments on commit 1f6fb61

Please sign in to comment.