diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 0c63fe7c..469ff423 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -32,8 +32,10 @@ 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-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 if: ${{ ! cancelled() }} @@ -45,7 +47,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-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 1162bb6c..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 @@ -12,7 +13,9 @@ parameters: - src scanDirectories: - - vendor + - /icingaweb2 + - /usr/share/icinga-php/vendor + - /usr/share/icinga-php/ipl ignoreErrors: - 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(); } 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) { 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); }