From c9aa7a19a90e9bff6acaba2998288b5078bf63ed Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Thu, 25 Jan 2024 03:08:21 +0100 Subject: [PATCH 1/5] phpstan: Streamline vendor file location with local dev-env phpstan is not run with an action anymore, as the action runs it its own docker container and hence has no access to files outside the repository root. A side-effect of this is, that phpstan now **really** runs with the php version set up by the matrix. --- .github/workflows/php.yml | 7 ++++--- phpstan.neon | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 0c63fe7c..5d15afee 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -32,8 +32,9 @@ jobs: - name: Setup dependencies run: | - composer require -n --no-progress overtrue/phplint - git clone --depth 1 https://github.com/Icinga/icingaweb2.git vendor/icingaweb2 + composer require -n --no-progress overtrue/phplint phpstan/phpstan + sudo git clone --depth 1 https://github.com/Icinga/icingaweb2.git /icingaweb2 + sudo git clone --depth 1 -b snapshot/nightly https://github.com/Icinga/icinga-php-thirdparty.git /usr/share/icinga-php/vendor - name: PHP Lint if: ${{ ! cancelled() }} @@ -45,7 +46,7 @@ jobs: - name: PHPStan if: ${{ ! cancelled() }} - uses: php-actions/phpstan@v3 + run: ./vendor/bin/phpstan analyse test: name: Unit tests with php ${{ matrix.php }} on ${{ matrix.os }} diff --git a/phpstan.neon b/phpstan.neon index 1162bb6c..4f4e6d7f 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -12,7 +12,8 @@ parameters: - src scanDirectories: - - vendor + - /icingaweb2 + - /usr/share/icinga-php/vendor ignoreErrors: - From 429ba25360e2ab3d6237ea6cc5a2b178d588b087 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Fri, 9 Feb 2024 15:06:08 +0100 Subject: [PATCH 2/5] ViewRenderer: Add type hints --- src/Compat/ViewRenderer.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Compat/ViewRenderer.php b/src/Compat/ViewRenderer.php index 48ddcc37..0eaa8ddc 100644 --- a/src/Compat/ViewRenderer.php +++ b/src/Compat/ViewRenderer.php @@ -2,11 +2,16 @@ namespace ipl\Web\Compat; +use Icinga\Web\View; +use ipl\Html\HtmlDocument; use Zend_Controller_Action_Helper_ViewRenderer as Zf1ViewRenderer; use Zend_Controller_Action_HelperBroker as Zf1HelperBroker; class ViewRenderer extends Zf1ViewRenderer { + /** @var View */ + public $view; + /** * Inject the view renderer */ @@ -41,9 +46,10 @@ public function getName() */ public function render($action = null, $name = null, $noController = null) { - $view = $this->view; + /** @var HtmlDocument $document */ + $document = $this->view->document; - if ($view->document->isEmpty() || $this->getRequest()->getParam('error_handler') !== null) { + if ($document->isEmpty() || $this->getRequest()->getParam('error_handler') !== null) { parent::render($action, $name, $noController); return; @@ -53,7 +59,7 @@ public function render($action = null, $name = null, $noController = null) $name = $this->getResponseSegment(); } - $this->getResponse()->appendBody($view->document->render(), $name); + $this->getResponse()->appendBody($document->render(), $name); $this->setNoRender(); } From 9a15b3c5ddcd21b1ca28e1fbb6801e0ab3b05f16 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Fri, 9 Feb 2024 15:21:44 +0100 Subject: [PATCH 3/5] PaginationControl: Drop useless comparison --- src/Control/PaginationControl.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Control/PaginationControl.php b/src/Control/PaginationControl.php index 00f5c207..e37d10a5 100644 --- a/src/Control/PaginationControl.php +++ b/src/Control/PaginationControl.php @@ -467,10 +467,8 @@ protected function createPageSelectorItem() 'title' => t('Go to page …') ]); - if (isset($currentPageNumber)) { - if ($currentPageNumber === 1 || $currentPageNumber === $this->getPageCount()) { - $select->add(Html::tag('option', ['disabled' => '', 'selected' => ''], '…')); - } + if ($currentPageNumber === 1 || $currentPageNumber === $this->getPageCount()) { + $select->add(Html::tag('option', ['disabled' => '', 'selected' => ''], '…')); } foreach (range(2, $this->getPageCount() - 1) as $page) { From 7d33f0451b3b2f4cb18983d97ff76c34d005c99c Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Fri, 9 Feb 2024 16:08:59 +0100 Subject: [PATCH 4/5] TermInput: Improve type hints --- src/FormElement/TermInput.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/FormElement/TermInput.php b/src/FormElement/TermInput.php index 352cce44..184be1da 100644 --- a/src/FormElement/TermInput.php +++ b/src/FormElement/TermInput.php @@ -151,14 +151,14 @@ public function getValue($name = null, $default = null) public function setValue($value) { - $recipients = $value; + $separatedTerms = $value; if (is_array($value)) { - $recipients = $value['value'] ?? ''; + $separatedTerms = $value['value'] ?? ''; parent::setValue($value); } $terms = []; - foreach ($this->parseValue($recipients) as $term) { + foreach ($this->parseValue((string) $separatedTerms) as $term) { $terms[] = new RegisteredTerm($term); } From 4a73bc66bd654d5de227f05e3e54735d9d472c67 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Fri, 9 Feb 2024 15:07:51 +0100 Subject: [PATCH 5/5] Update phpstan baseline --- .github/workflows/php.yml | 1 + phpstan-baseline-7x.neon | 41 +++++++++++ phpstan-baseline-8x.neon | 46 ++++++++++++ phpstan-baseline-by-php-version.php | 12 ++++ ...ine.neon => phpstan-baseline-standard.neon | 72 ++----------------- phpstan.neon | 4 +- 6 files changed, 109 insertions(+), 67 deletions(-) create mode 100644 phpstan-baseline-7x.neon create mode 100644 phpstan-baseline-8x.neon create mode 100644 phpstan-baseline-by-php-version.php rename phpstan-baseline.neon => phpstan-baseline-standard.neon (97%) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 5d15afee..469ff423 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -34,6 +34,7 @@ jobs: run: | composer require -n --no-progress overtrue/phplint phpstan/phpstan sudo git clone --depth 1 https://github.com/Icinga/icingaweb2.git /icingaweb2 + sudo git clone --depth 1 -b snapshot/nightly https://github.com/Icinga/icinga-php-library.git /usr/share/icinga-php/ipl sudo git clone --depth 1 -b snapshot/nightly https://github.com/Icinga/icinga-php-thirdparty.git /usr/share/icinga-php/vendor - name: PHP Lint diff --git a/phpstan-baseline-7x.neon b/phpstan-baseline-7x.neon new file mode 100644 index 00000000..07046c13 --- /dev/null +++ b/phpstan-baseline-7x.neon @@ -0,0 +1,41 @@ +parameters: + ignoreErrors: + - + message: "#^Parameter \\#2 \\$args of function vsprintf expects array\\, array\\ given\\.$#" + count: 1 + path: src/Compat/CompatController.php + + - + message: "#^Parameter \\#3 \\$length of function substr expects int, int\\<0, max\\>\\|false given\\.$#" + count: 1 + path: src/Control/SearchBar/Suggestions.php + + - + message: "#^Parameter \\#1 \\$str of function rawurlencode expects string, mixed given\\.$#" + count: 1 + path: src/Control/SearchBar/Terms.php + + - + message: "#^Parameter \\#1 \\$str of function strtolower expects string, mixed given\\.$#" + count: 1 + path: src/Control/SortControl.php + + - + message: "#^Parameter \\#2 \\$str of function explode expects string, int\\|string\\|null given\\.$#" + count: 1 + path: src/Control/SortControl.php + + - + message: "#^Parameter \\#1 \\$str of function rawurlencode expects string, mixed given\\.$#" + count: 1 + path: src/Filter/Renderer.php + + - + message: "#^Parameter \\#1 \\$stack of function array_push expects array, mixed given\\.$#" + count: 1 + path: src/FormElement/TermInput.php + + - + message: "#^Parameter \\#1 \\$content of static method ipl\\\\Html\\\\Text\\:\\:create\\(\\) expects string, string\\|false\\|null given\\.$#" + count: 1 + path: src/Widget/Tabs.php diff --git a/phpstan-baseline-8x.neon b/phpstan-baseline-8x.neon new file mode 100644 index 00000000..8d27b270 --- /dev/null +++ b/phpstan-baseline-8x.neon @@ -0,0 +1,46 @@ +parameters: + ignoreErrors: + - + message: "#^Parameter \\#2 \\$values of function vsprintf expects array\\, array\\ given\\.$#" + count: 1 + path: src/Compat/CompatController.php + + - + message: "#^Parameter \\#3 \\$length of function substr expects int\\|null, int\\|false given\\.$#" + count: 1 + path: src/Control/SearchBar/Suggestions.php + + - + message: "#^Parameter \\#1 \\$string of function rawurlencode expects string, mixed given\\.$#" + count: 1 + path: src/Control/SearchBar/Terms.php + + - + message: "#^Parameter \\#1 \\$string of function strtolower expects string, mixed given\\.$#" + count: 1 + path: src/Control/SortControl.php + + - + message: "#^Parameter \\#2 \\$string of function explode expects string, int\\|string\\|null given\\.$#" + count: 1 + path: src/Control/SortControl.php + + - + message: "#^Parameter \\#1 \\$column of method ipl\\\\Web\\\\Filter\\\\Parser\\:\\:createCondition\\(\\) expects string, string\\|false given\\.$#" + count: 1 + path: src/Filter/Parser.php + + - + message: "#^Parameter \\#1 \\$string of function rawurlencode expects string, mixed given\\.$#" + count: 1 + path: src/Filter/Renderer.php + + - + message: "#^Parameter \\#1 \\$array of function array_push expects array, mixed given\\.$#" + count: 1 + path: src/FormElement/TermInput.php + + - + message: "#^Parameter \\#1 \\$content of static method ipl\\\\Html\\\\Text\\:\\:create\\(\\) expects string, string\\|null given\\.$#" + count: 1 + path: src/Widget/Tabs.php diff --git a/phpstan-baseline-by-php-version.php b/phpstan-baseline-by-php-version.php new file mode 100644 index 00000000..05107dfd --- /dev/null +++ b/phpstan-baseline-by-php-version.php @@ -0,0 +1,12 @@ + $includes +]; diff --git a/phpstan-baseline.neon b/phpstan-baseline-standard.neon similarity index 97% rename from phpstan-baseline.neon rename to phpstan-baseline-standard.neon index be10aeb0..37045318 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline-standard.neon @@ -80,11 +80,6 @@ parameters: count: 1 path: src/Compat/CompatController.php - - - message: "#^Parameter \\#2 \\$values of function vsprintf expects array\\, array\\ given\\.$#" - count: 1 - path: src/Compat/CompatController.php - - message: "#^Property ipl\\\\Web\\\\Compat\\\\CompatController\\:\\:\\$parts type has no value type specified in iterable type array\\.$#" count: 1 @@ -100,11 +95,6 @@ parameters: count: 1 path: src/Compat/Multipart.php - - - message: "#^Access to an undefined property Zend_View_Interface\\:\\:\\$document\\.$#" - count: 2 - path: src/Compat/ViewRenderer.php - - message: "#^Method ipl\\\\Web\\\\Compat\\\\ViewRenderer\\:\\:inject\\(\\) has no return type specified\\.$#" count: 1 @@ -167,7 +157,7 @@ parameters: - message: "#^Cannot access offset 'terms' on mixed\\.$#" - count: 2 + count: 1 path: src/Control/SearchBar.php - @@ -175,11 +165,6 @@ parameters: count: 2 path: src/Control/SearchBar.php - - - message: "#^Cannot access offset mixed on array\\|object\\.$#" - count: 1 - path: src/Control/SearchBar.php - - message: "#^Cannot call method getHeaderLine\\(\\) on Psr\\\\Http\\\\Message\\\\ServerRequestInterface\\|null\\.$#" count: 1 @@ -247,7 +232,7 @@ parameters: - message: "#^Cannot access offset 'column' on mixed\\.$#" - count: 3 + count: 1 path: src/Control/SearchBar/Suggestions.php - @@ -257,7 +242,7 @@ parameters: - message: "#^Cannot access offset 'operator' on mixed\\.$#" - count: 2 + count: 1 path: src/Control/SearchBar/Suggestions.php - @@ -267,12 +252,12 @@ parameters: - message: "#^Cannot access offset 'searchFilter' on mixed\\.$#" - count: 2 + count: 1 path: src/Control/SearchBar/Suggestions.php - message: "#^Cannot access offset 'showQuickSearch' on mixed\\.$#" - count: 2 + count: 1 path: src/Control/SearchBar/Suggestions.php - @@ -415,11 +400,6 @@ parameters: count: 1 path: src/Control/SearchBar/Suggestions.php - - - message: "#^Parameter \\#3 \\$length of function substr expects int\\|null, int\\|false given\\.$#" - count: 1 - path: src/Control/SearchBar/Suggestions.php - - message: "#^Parameter \\#3 \\$searchFilter of method ipl\\\\Web\\\\Control\\\\SearchBar\\\\Suggestions\\:\\:fetchValueSuggestions\\(\\) expects ipl\\\\Stdlib\\\\Filter\\\\Chain, ipl\\\\Stdlib\\\\Filter\\\\Rule given\\.$#" count: 1 @@ -490,11 +470,6 @@ parameters: count: 1 path: src/Control/SearchBar/Terms.php - - - message: "#^Parameter \\#1 \\$string of function rawurlencode expects string, mixed given\\.$#" - count: 1 - path: src/Control/SearchBar/Terms.php - - message: "#^Property ipl\\\\Web\\\\Control\\\\SearchBar\\\\Terms\\:\\:\\$changes type has no value type specified in iterable type array\\.$#" count: 1 @@ -685,11 +660,6 @@ parameters: count: 3 path: src/Control/SortControl.php - - - message: "#^Cannot access offset mixed on array\\|object\\.$#" - count: 1 - path: src/Control/SortControl.php - - message: "#^Cannot call method getParsedBody\\(\\) on Psr\\\\Http\\\\Message\\\\ServerRequestInterface\\|null\\.$#" count: 1 @@ -730,21 +700,11 @@ parameters: count: 1 path: src/Control/SortControl.php - - - message: "#^Parameter \\#1 \\$string of function strtolower expects string, mixed given\\.$#" - count: 1 - path: src/Control/SortControl.php - - message: "#^Parameter \\#2 \\$start of static method ipl\\\\Stdlib\\\\Str\\:\\:startsWith\\(\\) expects string, mixed given\\.$#" count: 1 path: src/Control/SortControl.php - - - message: "#^Parameter \\#2 \\$string of function explode expects string, int\\|string\\|null given\\.$#" - count: 1 - path: src/Control/SortControl.php - - message: "#^Part \\$column \\(mixed\\) of encapsed string cannot be cast to string\\.$#" count: 3 @@ -815,11 +775,6 @@ parameters: count: 1 path: src/Filter/Parser.php - - - message: "#^Parameter \\#1 \\$column of method ipl\\\\Web\\\\Filter\\\\Parser\\:\\:createCondition\\(\\) expects string, string\\|false given\\.$#" - count: 1 - path: src/Filter/Parser.php - - message: "#^Parameter \\#1 \\$column of static method ipl\\\\Stdlib\\\\Filter\\:\\:equal\\(\\) expects string, string\\|false given\\.$#" count: 1 @@ -885,11 +840,6 @@ parameters: count: 2 path: src/Filter/Parser.php - - - message: "#^Parameter \\#1 \\$string of function rawurlencode expects string, mixed given\\.$#" - count: 1 - path: src/Filter/Renderer.php - - message: "#^Binary operation \"\\.\" between 'desc_' and array\\|bool\\|string\\|null results in an error\\.$#" count: 1 @@ -1430,11 +1380,6 @@ parameters: count: 1 path: src/FormElement/TermInput.php - - - message: "#^Parameter \\#1 \\$array of function array_push expects array, mixed given\\.$#" - count: 1 - path: src/FormElement/TermInput.php - - message: "#^Parameter \\#1 \\$content of static method ipl\\\\Html\\\\Text\\:\\:create\\(\\) expects string, string\\|false given\\.$#" count: 3 @@ -1452,7 +1397,7 @@ parameters: - message: "#^Parameter \\#1 \\$value of method ipl\\\\Web\\\\FormElement\\\\TermInput\\:\\:parseValue\\(\\) expects string, mixed given\\.$#" - count: 2 + count: 1 path: src/FormElement/TermInput.php - @@ -1635,11 +1580,6 @@ parameters: count: 1 path: src/Widget/Tabs.php - - - message: "#^Parameter \\#1 \\$content of static method ipl\\\\Html\\\\Text\\:\\:create\\(\\) expects string, string\\|null given\\.$#" - count: 1 - path: src/Widget/Tabs.php - - message: "#^Parameter \\#2 \\$tab of method Icinga\\\\Web\\\\Widget\\\\Tabs\\:\\:add\\(\\) expects array\\|Icinga\\\\Web\\\\Widget\\\\Tab, mixed given\\.$#" count: 1 diff --git a/phpstan.neon b/phpstan.neon index 4f4e6d7f..25304300 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,6 @@ includes: - - phpstan-baseline.neon + - phpstan-baseline-standard.neon + - phpstan-baseline-by-php-version.php parameters: level: max @@ -14,6 +15,7 @@ parameters: scanDirectories: - /icingaweb2 - /usr/share/icinga-php/vendor + - /usr/share/icinga-php/ipl ignoreErrors: -