Skip to content

Commit 68667fe

Browse files
authored
phpstan: Streamline vendor file location with local dev-env (#215)
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.
2 parents c57458a + 4a73bc6 commit 68667fe

File tree

9 files changed

+129
-81
lines changed

9 files changed

+129
-81
lines changed

.github/workflows/php.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ jobs:
3232

3333
- name: Setup dependencies
3434
run: |
35-
composer require -n --no-progress overtrue/phplint
36-
git clone --depth 1 https://github.com/Icinga/icingaweb2.git vendor/icingaweb2
35+
composer require -n --no-progress overtrue/phplint phpstan/phpstan
36+
sudo git clone --depth 1 https://github.com/Icinga/icingaweb2.git /icingaweb2
37+
sudo git clone --depth 1 -b snapshot/nightly https://github.com/Icinga/icinga-php-library.git /usr/share/icinga-php/ipl
38+
sudo git clone --depth 1 -b snapshot/nightly https://github.com/Icinga/icinga-php-thirdparty.git /usr/share/icinga-php/vendor
3739
3840
- name: PHP Lint
3941
if: ${{ ! cancelled() }}
@@ -45,7 +47,7 @@ jobs:
4547

4648
- name: PHPStan
4749
if: ${{ ! cancelled() }}
48-
uses: php-actions/phpstan@v3
50+
run: ./vendor/bin/phpstan analyse
4951

5052
test:
5153
name: Unit tests with php ${{ matrix.php }} on ${{ matrix.os }}

phpstan-baseline-7x.neon

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
parameters:
2+
ignoreErrors:
3+
-
4+
message: "#^Parameter \\#2 \\$args of function vsprintf expects array\\<bool\\|float\\|int\\|string\\|null\\>, array\\<int, mixed\\> given\\.$#"
5+
count: 1
6+
path: src/Compat/CompatController.php
7+
8+
-
9+
message: "#^Parameter \\#3 \\$length of function substr expects int, int\\<0, max\\>\\|false given\\.$#"
10+
count: 1
11+
path: src/Control/SearchBar/Suggestions.php
12+
13+
-
14+
message: "#^Parameter \\#1 \\$str of function rawurlencode expects string, mixed given\\.$#"
15+
count: 1
16+
path: src/Control/SearchBar/Terms.php
17+
18+
-
19+
message: "#^Parameter \\#1 \\$str of function strtolower expects string, mixed given\\.$#"
20+
count: 1
21+
path: src/Control/SortControl.php
22+
23+
-
24+
message: "#^Parameter \\#2 \\$str of function explode expects string, int\\|string\\|null given\\.$#"
25+
count: 1
26+
path: src/Control/SortControl.php
27+
28+
-
29+
message: "#^Parameter \\#1 \\$str of function rawurlencode expects string, mixed given\\.$#"
30+
count: 1
31+
path: src/Filter/Renderer.php
32+
33+
-
34+
message: "#^Parameter \\#1 \\$stack of function array_push expects array, mixed given\\.$#"
35+
count: 1
36+
path: src/FormElement/TermInput.php
37+
38+
-
39+
message: "#^Parameter \\#1 \\$content of static method ipl\\\\Html\\\\Text\\:\\:create\\(\\) expects string, string\\|false\\|null given\\.$#"
40+
count: 1
41+
path: src/Widget/Tabs.php

phpstan-baseline-8x.neon

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
parameters:
2+
ignoreErrors:
3+
-
4+
message: "#^Parameter \\#2 \\$values of function vsprintf expects array\\<bool\\|float\\|int\\|string\\|null\\>, array\\<int\\|string, mixed\\> given\\.$#"
5+
count: 1
6+
path: src/Compat/CompatController.php
7+
8+
-
9+
message: "#^Parameter \\#3 \\$length of function substr expects int\\|null, int\\|false given\\.$#"
10+
count: 1
11+
path: src/Control/SearchBar/Suggestions.php
12+
13+
-
14+
message: "#^Parameter \\#1 \\$string of function rawurlencode expects string, mixed given\\.$#"
15+
count: 1
16+
path: src/Control/SearchBar/Terms.php
17+
18+
-
19+
message: "#^Parameter \\#1 \\$string of function strtolower expects string, mixed given\\.$#"
20+
count: 1
21+
path: src/Control/SortControl.php
22+
23+
-
24+
message: "#^Parameter \\#2 \\$string of function explode expects string, int\\|string\\|null given\\.$#"
25+
count: 1
26+
path: src/Control/SortControl.php
27+
28+
-
29+
message: "#^Parameter \\#1 \\$column of method ipl\\\\Web\\\\Filter\\\\Parser\\:\\:createCondition\\(\\) expects string, string\\|false given\\.$#"
30+
count: 1
31+
path: src/Filter/Parser.php
32+
33+
-
34+
message: "#^Parameter \\#1 \\$string of function rawurlencode expects string, mixed given\\.$#"
35+
count: 1
36+
path: src/Filter/Renderer.php
37+
38+
-
39+
message: "#^Parameter \\#1 \\$array of function array_push expects array, mixed given\\.$#"
40+
count: 1
41+
path: src/FormElement/TermInput.php
42+
43+
-
44+
message: "#^Parameter \\#1 \\$content of static method ipl\\\\Html\\\\Text\\:\\:create\\(\\) expects string, string\\|null given\\.$#"
45+
count: 1
46+
path: src/Widget/Tabs.php

phpstan-baseline-by-php-version.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
$includes = [];
4+
if (PHP_VERSION_ID < 80000) {
5+
$includes[] = __DIR__ . '/phpstan-baseline-7x.neon';
6+
} else {
7+
$includes[] = __DIR__ . '/phpstan-baseline-8x.neon';
8+
}
9+
10+
return [
11+
'includes' => $includes
12+
];

phpstan-baseline.neon renamed to phpstan-baseline-standard.neon

Lines changed: 6 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,6 @@ parameters:
8080
count: 1
8181
path: src/Compat/CompatController.php
8282

83-
-
84-
message: "#^Parameter \\#2 \\$values of function vsprintf expects array\\<bool\\|float\\|int\\|string\\|null\\>, array\\<int\\|string, mixed\\> given\\.$#"
85-
count: 1
86-
path: src/Compat/CompatController.php
87-
8883
-
8984
message: "#^Property ipl\\\\Web\\\\Compat\\\\CompatController\\:\\:\\$parts type has no value type specified in iterable type array\\.$#"
9085
count: 1
@@ -100,11 +95,6 @@ parameters:
10095
count: 1
10196
path: src/Compat/Multipart.php
10297

103-
-
104-
message: "#^Access to an undefined property Zend_View_Interface\\:\\:\\$document\\.$#"
105-
count: 2
106-
path: src/Compat/ViewRenderer.php
107-
10898
-
10999
message: "#^Method ipl\\\\Web\\\\Compat\\\\ViewRenderer\\:\\:inject\\(\\) has no return type specified\\.$#"
110100
count: 1
@@ -167,19 +157,14 @@ parameters:
167157

168158
-
169159
message: "#^Cannot access offset 'terms' on mixed\\.$#"
170-
count: 2
160+
count: 1
171161
path: src/Control/SearchBar.php
172162

173163
-
174164
message: "#^Cannot access offset 'type' on mixed\\.$#"
175165
count: 2
176166
path: src/Control/SearchBar.php
177167

178-
-
179-
message: "#^Cannot access offset mixed on array\\|object\\.$#"
180-
count: 1
181-
path: src/Control/SearchBar.php
182-
183168
-
184169
message: "#^Cannot call method getHeaderLine\\(\\) on Psr\\\\Http\\\\Message\\\\ServerRequestInterface\\|null\\.$#"
185170
count: 1
@@ -247,7 +232,7 @@ parameters:
247232

248233
-
249234
message: "#^Cannot access offset 'column' on mixed\\.$#"
250-
count: 3
235+
count: 1
251236
path: src/Control/SearchBar/Suggestions.php
252237

253238
-
@@ -257,7 +242,7 @@ parameters:
257242

258243
-
259244
message: "#^Cannot access offset 'operator' on mixed\\.$#"
260-
count: 2
245+
count: 1
261246
path: src/Control/SearchBar/Suggestions.php
262247

263248
-
@@ -267,12 +252,12 @@ parameters:
267252

268253
-
269254
message: "#^Cannot access offset 'searchFilter' on mixed\\.$#"
270-
count: 2
255+
count: 1
271256
path: src/Control/SearchBar/Suggestions.php
272257

273258
-
274259
message: "#^Cannot access offset 'showQuickSearch' on mixed\\.$#"
275-
count: 2
260+
count: 1
276261
path: src/Control/SearchBar/Suggestions.php
277262

278263
-
@@ -415,11 +400,6 @@ parameters:
415400
count: 1
416401
path: src/Control/SearchBar/Suggestions.php
417402

418-
-
419-
message: "#^Parameter \\#3 \\$length of function substr expects int\\|null, int\\|false given\\.$#"
420-
count: 1
421-
path: src/Control/SearchBar/Suggestions.php
422-
423403
-
424404
message: "#^Parameter \\#3 \\$searchFilter of method ipl\\\\Web\\\\Control\\\\SearchBar\\\\Suggestions\\:\\:fetchValueSuggestions\\(\\) expects ipl\\\\Stdlib\\\\Filter\\\\Chain, ipl\\\\Stdlib\\\\Filter\\\\Rule given\\.$#"
425405
count: 1
@@ -490,11 +470,6 @@ parameters:
490470
count: 1
491471
path: src/Control/SearchBar/Terms.php
492472

493-
-
494-
message: "#^Parameter \\#1 \\$string of function rawurlencode expects string, mixed given\\.$#"
495-
count: 1
496-
path: src/Control/SearchBar/Terms.php
497-
498473
-
499474
message: "#^Property ipl\\\\Web\\\\Control\\\\SearchBar\\\\Terms\\:\\:\\$changes type has no value type specified in iterable type array\\.$#"
500475
count: 1
@@ -685,11 +660,6 @@ parameters:
685660
count: 3
686661
path: src/Control/SortControl.php
687662

688-
-
689-
message: "#^Cannot access offset mixed on array\\|object\\.$#"
690-
count: 1
691-
path: src/Control/SortControl.php
692-
693663
-
694664
message: "#^Cannot call method getParsedBody\\(\\) on Psr\\\\Http\\\\Message\\\\ServerRequestInterface\\|null\\.$#"
695665
count: 1
@@ -730,21 +700,11 @@ parameters:
730700
count: 1
731701
path: src/Control/SortControl.php
732702

733-
-
734-
message: "#^Parameter \\#1 \\$string of function strtolower expects string, mixed given\\.$#"
735-
count: 1
736-
path: src/Control/SortControl.php
737-
738703
-
739704
message: "#^Parameter \\#2 \\$start of static method ipl\\\\Stdlib\\\\Str\\:\\:startsWith\\(\\) expects string, mixed given\\.$#"
740705
count: 1
741706
path: src/Control/SortControl.php
742707

743-
-
744-
message: "#^Parameter \\#2 \\$string of function explode expects string, int\\|string\\|null given\\.$#"
745-
count: 1
746-
path: src/Control/SortControl.php
747-
748708
-
749709
message: "#^Part \\$column \\(mixed\\) of encapsed string cannot be cast to string\\.$#"
750710
count: 3
@@ -815,11 +775,6 @@ parameters:
815775
count: 1
816776
path: src/Filter/Parser.php
817777

818-
-
819-
message: "#^Parameter \\#1 \\$column of method ipl\\\\Web\\\\Filter\\\\Parser\\:\\:createCondition\\(\\) expects string, string\\|false given\\.$#"
820-
count: 1
821-
path: src/Filter/Parser.php
822-
823778
-
824779
message: "#^Parameter \\#1 \\$column of static method ipl\\\\Stdlib\\\\Filter\\:\\:equal\\(\\) expects string, string\\|false given\\.$#"
825780
count: 1
@@ -885,11 +840,6 @@ parameters:
885840
count: 2
886841
path: src/Filter/Parser.php
887842

888-
-
889-
message: "#^Parameter \\#1 \\$string of function rawurlencode expects string, mixed given\\.$#"
890-
count: 1
891-
path: src/Filter/Renderer.php
892-
893843
-
894844
message: "#^Binary operation \"\\.\" between 'desc_' and array\\|bool\\|string\\|null results in an error\\.$#"
895845
count: 1
@@ -1430,11 +1380,6 @@ parameters:
14301380
count: 1
14311381
path: src/FormElement/TermInput.php
14321382

1433-
-
1434-
message: "#^Parameter \\#1 \\$array of function array_push expects array, mixed given\\.$#"
1435-
count: 1
1436-
path: src/FormElement/TermInput.php
1437-
14381383
-
14391384
message: "#^Parameter \\#1 \\$content of static method ipl\\\\Html\\\\Text\\:\\:create\\(\\) expects string, string\\|false given\\.$#"
14401385
count: 3
@@ -1452,7 +1397,7 @@ parameters:
14521397

14531398
-
14541399
message: "#^Parameter \\#1 \\$value of method ipl\\\\Web\\\\FormElement\\\\TermInput\\:\\:parseValue\\(\\) expects string, mixed given\\.$#"
1455-
count: 2
1400+
count: 1
14561401
path: src/FormElement/TermInput.php
14571402

14581403
-
@@ -1635,11 +1580,6 @@ parameters:
16351580
count: 1
16361581
path: src/Widget/Tabs.php
16371582

1638-
-
1639-
message: "#^Parameter \\#1 \\$content of static method ipl\\\\Html\\\\Text\\:\\:create\\(\\) expects string, string\\|null given\\.$#"
1640-
count: 1
1641-
path: src/Widget/Tabs.php
1642-
16431583
-
16441584
message: "#^Parameter \\#2 \\$tab of method Icinga\\\\Web\\\\Widget\\\\Tabs\\:\\:add\\(\\) expects array\\|Icinga\\\\Web\\\\Widget\\\\Tab, mixed given\\.$#"
16451585
count: 1

phpstan.neon

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
includes:
2-
- phpstan-baseline.neon
2+
- phpstan-baseline-standard.neon
3+
- phpstan-baseline-by-php-version.php
34

45
parameters:
56
level: max
@@ -12,7 +13,9 @@ parameters:
1213
- src
1314

1415
scanDirectories:
15-
- vendor
16+
- /icingaweb2
17+
- /usr/share/icinga-php/vendor
18+
- /usr/share/icinga-php/ipl
1619

1720
ignoreErrors:
1821
-

src/Compat/ViewRenderer.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@
22

33
namespace ipl\Web\Compat;
44

5+
use Icinga\Web\View;
6+
use ipl\Html\HtmlDocument;
57
use Zend_Controller_Action_Helper_ViewRenderer as Zf1ViewRenderer;
68
use Zend_Controller_Action_HelperBroker as Zf1HelperBroker;
79

810
class ViewRenderer extends Zf1ViewRenderer
911
{
12+
/** @var View */
13+
public $view;
14+
1015
/**
1116
* Inject the view renderer
1217
*/
@@ -41,9 +46,10 @@ public function getName()
4146
*/
4247
public function render($action = null, $name = null, $noController = null)
4348
{
44-
$view = $this->view;
49+
/** @var HtmlDocument $document */
50+
$document = $this->view->document;
4551

46-
if ($view->document->isEmpty() || $this->getRequest()->getParam('error_handler') !== null) {
52+
if ($document->isEmpty() || $this->getRequest()->getParam('error_handler') !== null) {
4753
parent::render($action, $name, $noController);
4854

4955
return;
@@ -53,7 +59,7 @@ public function render($action = null, $name = null, $noController = null)
5359
$name = $this->getResponseSegment();
5460
}
5561

56-
$this->getResponse()->appendBody($view->document->render(), $name);
62+
$this->getResponse()->appendBody($document->render(), $name);
5763

5864
$this->setNoRender();
5965
}

src/Control/PaginationControl.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -467,10 +467,8 @@ protected function createPageSelectorItem()
467467
'title' => t('Go to page …')
468468
]);
469469

470-
if (isset($currentPageNumber)) {
471-
if ($currentPageNumber === 1 || $currentPageNumber === $this->getPageCount()) {
472-
$select->add(Html::tag('option', ['disabled' => '', 'selected' => ''], ''));
473-
}
470+
if ($currentPageNumber === 1 || $currentPageNumber === $this->getPageCount()) {
471+
$select->add(Html::tag('option', ['disabled' => '', 'selected' => ''], ''));
474472
}
475473

476474
foreach (range(2, $this->getPageCount() - 1) as $page) {

0 commit comments

Comments
 (0)