Skip to content

Commit

Permalink
phpstan: Streamline vendor file location with local dev-env (#215)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nilmerg authored Feb 9, 2024
2 parents c57458a + 4a73bc6 commit 68667fe
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 81 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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() }}
Expand All @@ -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 }}
Expand Down
41 changes: 41 additions & 0 deletions phpstan-baseline-7x.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
parameters:
ignoreErrors:
-
message: "#^Parameter \\#2 \\$args of function vsprintf expects array\\<bool\\|float\\|int\\|string\\|null\\>, array\\<int, mixed\\> 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
46 changes: 46 additions & 0 deletions phpstan-baseline-8x.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
parameters:
ignoreErrors:
-
message: "#^Parameter \\#2 \\$values of function vsprintf expects array\\<bool\\|float\\|int\\|string\\|null\\>, array\\<int\\|string, mixed\\> 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
12 changes: 12 additions & 0 deletions phpstan-baseline-by-php-version.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

$includes = [];
if (PHP_VERSION_ID < 80000) {
$includes[] = __DIR__ . '/phpstan-baseline-7x.neon';
} else {
$includes[] = __DIR__ . '/phpstan-baseline-8x.neon';
}

return [
'includes' => $includes
];
72 changes: 6 additions & 66 deletions phpstan-baseline.neon → phpstan-baseline-standard.neon
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,6 @@ parameters:
count: 1
path: src/Compat/CompatController.php

-
message: "#^Parameter \\#2 \\$values of function vsprintf expects array\\<bool\\|float\\|int\\|string\\|null\\>, array\\<int\\|string, mixed\\> 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
Expand All @@ -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
Expand Down Expand Up @@ -167,19 +157,14 @@ parameters:

-
message: "#^Cannot access offset 'terms' on mixed\\.$#"
count: 2
count: 1
path: src/Control/SearchBar.php

-
message: "#^Cannot access offset 'type' on mixed\\.$#"
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
Expand Down Expand Up @@ -247,7 +232,7 @@ parameters:

-
message: "#^Cannot access offset 'column' on mixed\\.$#"
count: 3
count: 1
path: src/Control/SearchBar/Suggestions.php

-
Expand All @@ -257,7 +242,7 @@ parameters:

-
message: "#^Cannot access offset 'operator' on mixed\\.$#"
count: 2
count: 1
path: src/Control/SearchBar/Suggestions.php

-
Expand All @@ -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

-
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

-
Expand Down Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
includes:
- phpstan-baseline.neon
- phpstan-baseline-standard.neon
- phpstan-baseline-by-php-version.php

parameters:
level: max
Expand All @@ -12,7 +13,9 @@ parameters:
- src

scanDirectories:
- vendor
- /icingaweb2
- /usr/share/icinga-php/vendor
- /usr/share/icinga-php/ipl

ignoreErrors:
-
Expand Down
12 changes: 9 additions & 3 deletions src/Compat/ViewRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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;
Expand All @@ -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();
}
Expand Down
6 changes: 2 additions & 4 deletions src/Control/PaginationControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading

0 comments on commit 68667fe

Please sign in to comment.