Skip to content

Commit 4a0d2b9

Browse files
committed
Migrate to PHPStan
1 parent 5a0fe2e commit 4a0d2b9

File tree

8 files changed

+34
-90
lines changed

8 files changed

+34
-90
lines changed

.github/workflows/php.yml

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,9 @@ jobs:
5050
uses: shivammathur/setup-php@v2
5151
with:
5252
# Should be the higest supported version, so we can use the newest tools
53-
php-version: '8.3'
54-
tools: composer, composer-require-checker, composer-unused, phpcs, psalm
55-
# optional performance gain for psalm: opcache
56-
extensions: ctype, date, dom, fileinfo, filter, hash, intl, mbstring, opcache, openssl, pcre, pdo, posix, spl, xml
53+
php-version: '8.4'
54+
tools: composer, composer-require-checker, composer-unused, phpcs, phpstan
55+
extensions: ctype, date, dom, fileinfo, filter, hash, intl, mbstring, openssl, pcre, pdo, posix, spl, xml
5756

5857
- name: Setup problem matchers for PHP
5958
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"
@@ -85,27 +84,13 @@ jobs:
8584
- name: PHP Code Sniffer
8685
run: phpcs
8786

88-
- name: Psalm
89-
continue-on-error: true
90-
run: |
91-
psalm -c psalm.xml \
92-
--show-info=true \
93-
--shepherd \
94-
--php-version=${{ steps.setup-php.outputs.php-version }}
95-
96-
- name: Psalm (testsuite)
87+
- name: PHPStan
9788
run: |
98-
psalm -c psalm-dev.xml \
99-
--show-info=true \
100-
--shepherd \
101-
--php-version=${{ steps.setup-php.outputs.php-version }}
89+
vendor/bin/phpstan analyze -c phpstan.neon --debug
10290
103-
- name: Psalter
91+
- name: PHPStan (testsuite)
10492
run: |
105-
psalm --alter \
106-
--issues=UnnecessaryVarAnnotation \
107-
--dry-run \
108-
--php-version=${{ steps.setup-php.outputs.php-version }}
93+
vendor/bin/phpstan analyze -c phpstan-dev.neon --debug
10994
11095
security:
11196
name: Security checks
@@ -156,7 +141,7 @@ jobs:
156141
fail-fast: false
157142
matrix:
158143
operating-system: [ubuntu-latest]
159-
php-versions: ['8.1', '8.2', '8.3']
144+
php-versions: ['8.1', '8.2', '8.3', '8.4']
160145

161146
steps:
162147
- name: Setup PHP, with composer and extensions
@@ -196,15 +181,15 @@ jobs:
196181
run: composer install --no-progress --prefer-dist --optimize-autoloader
197182

198183
- name: Run unit tests with coverage
199-
if: ${{ matrix.php-versions == '8.3' }}
184+
if: ${{ matrix.php-versions == '8.4' }}
200185
run: vendor/bin/phpunit
201186

202187
- name: Run unit tests (no coverage)
203-
if: ${{ matrix.php-versions != '8.3' }}
188+
if: ${{ matrix.php-versions != '8.4' }}
204189
run: vendor/bin/phpunit --no-coverage
205190

206191
- name: Save coverage data
207-
if: ${{ matrix.php-versions == '8.3' }}
192+
if: ${{ matrix.php-versions == '8.4' }}
208193
uses: actions/upload-artifact@v4
209194
with:
210195
name: coverage-data
@@ -218,7 +203,7 @@ jobs:
218203
fail-fast: true
219204
matrix:
220205
operating-system: [windows-latest]
221-
php-versions: ['8.1', '8.2', '8.3']
206+
php-versions: ['8.1', '8.2', '8.3', '8.4']
222207

223208
steps:
224209
- name: Setup PHP, with composer and extensions

phpstan-baseline.neon

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
parameters:
2+
ignoreErrors:
3+
-
4+
message: "#^Strict comparison using \\=\\=\\= between mixed and null will always evaluate to false\\.$#"
5+
count: 1
6+
path: src/Auth/Source/PasswordVerify.php

phpstan-dev.neon

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
parameters:
2+
level: 9
3+
paths:
4+
- tests

phpstan.neon

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
parameters:
2+
level: 5
3+
paths:
4+
- src
5+
includes:
6+
- phpstan-baseline.neon

psalm-dev.xml

Lines changed: 0 additions & 27 deletions
This file was deleted.

psalm.xml

Lines changed: 0 additions & 30 deletions
This file was deleted.

src/Auth/Source/PasswordVerify.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ protected function login(string $username, string $password): array
142142
* This should never happen as the count(data) test above would have already thrown.
143143
* But checking twice doesn't hurt.
144144
*/
145-
if (is_null($pwhash)) {
145+
if ($pwhash === null) {
146146
if ($pwhash != $row[$this->passwordhashcolumn]) {
147147
Logger::error(sprintf(
148148
'sqlauth:%s: column `%s` does not contain a password hash.',

src/Auth/Source/SQL.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,12 @@ protected function connect(): PDO
158158
/**
159159
* Extract SQL columns into SAML attribute array
160160
*
161-
* @param $attributes output place to store extracted attributes
161+
* @param array $attributes output place to store extracted attributes
162162
* @param array $data Associative array from database in the format of PDO fetchAll
163163
* @param array $forbiddenAttributes An array of attributes to never return
164-
* @return $attributes
164+
* @return array $attributes
165165
*/
166-
protected function extractAttributes(&$attributes, $data, $forbiddenAttributes = [])
166+
protected function extractAttributes(array $attributes, array $data, array $forbiddenAttributes = []): array
167167
{
168168
foreach ($data as $row) {
169169
foreach ($row as $name => $value) {
@@ -195,8 +195,8 @@ protected function extractAttributes(&$attributes, $data, $forbiddenAttributes =
195195
* Execute the query with given parameters and return the tuples that result.
196196
*
197197
* @param string $query SQL to execute
198-
* @param array $params parameters to the SQL query
199-
* @return tuples that result
198+
* @param array $params parameters to the SQL query
199+
* @return array tuples that result
200200
*/
201201
protected function executeQuery(PDO $db, string $query, array $params): array
202202
{

0 commit comments

Comments
 (0)