Skip to content

Commit 6787763

Browse files
authored
Added phpstan configuration (#66)
* [Composer] Added phpstan/* dependencies * [PHPStan] Configured phpstan and initialized baseline * [GHA] Added PHPStan analysis step to CI workflow * [GHA] Bump PHP version for code style check and tests
1 parent 05bf88e commit 6787763

File tree

7 files changed

+1970
-2
lines changed

7 files changed

+1970
-2
lines changed

.github/workflows/ci.yaml

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
strategy:
1515
matrix:
1616
php:
17-
- '8.0'
17+
- '8.1'
1818
steps:
1919
- uses: actions/checkout@v2
2020

@@ -33,6 +33,32 @@ jobs:
3333
- name: Run code style check
3434
run: composer run-script check-cs -- --format=checkstyle | cs2pr
3535

36+
phpstan:
37+
name: Run PHPStan analysis
38+
runs-on: "ubuntu-24.04"
39+
strategy:
40+
matrix:
41+
php:
42+
- '7.4'
43+
- '8.3'
44+
steps:
45+
- uses: actions/checkout@v4
46+
47+
- name: Setup PHP Action
48+
uses: shivammathur/setup-php@v2
49+
with:
50+
php-version: ${{ matrix.php }}
51+
coverage: none
52+
extensions: 'pdo_sqlite, gd'
53+
tools: cs2pr
54+
55+
- uses: "ramsey/composer-install@v3"
56+
with:
57+
dependency-versions: "highest"
58+
59+
- name: Run PHPStan analysis
60+
run: composer run-script phpstan
61+
3662
tests:
3763
name: Tests
3864
runs-on: "ubuntu-24.04"
@@ -43,7 +69,7 @@ jobs:
4369
matrix:
4470
php:
4571
- '7.4'
46-
- '8.0'
72+
- '8.3'
4773
composer_options: [ "" ]
4874
include:
4975
- php: '8.1'

composer.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
"phpunit/phpunit": "^8.5",
3636
"matthiasnoback/symfony-dependency-injection-test": "^4.3",
3737
"phpspec/phpspec": "^7.1",
38+
"phpstan/phpstan": "^2.0",
39+
"phpstan/phpstan-phpunit": "^2.0",
40+
"phpstan/phpstan-symfony": "^2.0",
3841
"ibexa/code-style": "^1.0",
3942
"friendsofphp/php-cs-fixer": "^3.0",
4043
"symfony/phpunit-bridge": "^5.1"
@@ -59,6 +62,7 @@
5962
"unit": "phpunit -c phpunit.xml",
6063
"spec": "phpspec run --format=pretty",
6164
"check-cs": "@fix-cs --dry-run",
65+
"phpstan": "phpstan analyse",
6266
"test": [
6367
"@unit",
6468
"@spec"

ignore-by-php-version.neon.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
/**
4+
* @copyright Copyright (C) Ibexa AS. All rights reserved.
5+
* @license For full copyright and license information view LICENSE file distributed with this source code.
6+
*/
7+
declare(strict_types=1);
8+
9+
$includes = [];
10+
if (PHP_VERSION_ID >= 80000) {
11+
$includes[] = __DIR__ . '/ignore-gte-php8.0-errors.neon';
12+
} else {
13+
$includes[] = __DIR__ . '/ignore-php7.4-errors.neon';
14+
}
15+
16+
$config = [];
17+
$config['includes'] = $includes;
18+
19+
return $config;

ignore-gte-php8.0-errors.neon

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
parameters:
2+
ignoreErrors:
3+
-
4+
message: '#^Parameter \#2 \$string of function explode expects string, string\|null given\.$#'
5+
identifier: argument.type
6+
count: 1
7+
path: src/lib/EventSubscriber/XLocationIdResponseSubscriber.php
8+
-
9+
message: '#^Parameter \#1 \.\.\.\$arrays of function array_merge expects array, list\<string\>\|false given\.$#'
10+
identifier: argument.type
11+
count: 1
12+
path: src/lib/Handler/TagHandler.php
13+
-
14+
message: '#^Parameter \#2 \.\.\.\$arrays of function array_merge expects array, list\<string\>\|false given\.$#'
15+
identifier: argument.type
16+
count: 1
17+
path: src/lib/Handler/TagHandler.php
18+
19+
-
20+
message: '#^Parameter \#3 \$length of function substr expects int\|null, int\|false given\.$#'
21+
identifier: argument.type
22+
count: 1
23+
path: src/lib/Handler/TagHandler.php

ignore-php7.4-errors.neon

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
parameters:
2+
ignoreErrors:
3+
-
4+
message: '#^Parameter \#2 \$str of function explode expects string, string\|null given\.$#'
5+
identifier: argument.type
6+
count: 1
7+
path: src/lib/EventSubscriber/XLocationIdResponseSubscriber.php
8+
-
9+
message: '#^Parameter \#1 \$arr1 of function array_merge expects array, list\<string\>\|false given\.$#'
10+
identifier: argument.type
11+
count: 1
12+
path: src/lib/Handler/TagHandler.php
13+
-
14+
message: '#^Parameter \#2 \.\.\.\$args of function array_merge expects array, list\<string\>\|false given\.$#'
15+
identifier: argument.type
16+
count: 1
17+
path: src/lib/Handler/TagHandler.php
18+
19+
-
20+
message: '#^Parameter \#3 \$length of function substr expects int, int\<0, max\>\|false given\.$#'
21+
identifier: argument.type
22+
count: 1
23+
path: src/lib/Handler/TagHandler.php

0 commit comments

Comments
 (0)