Skip to content

Commit 9bf3af4

Browse files
trashercedric-anne
andauthored
Setup phpstan with Safe-PHP (#19689)
* Setup phpstan with Safe-PHP see https://github.com/thecodingmachine/safe * Add all errors to baseline * Fix an issue to prevent unused dependency issue * Error differs depending on PHP versions --------- Co-authored-by: Cédric Anne <cedric.anne@gmail.com>
1 parent eae1896 commit 9bf3af4

File tree

7 files changed

+8871
-2483
lines changed

7 files changed

+8871
-2483
lines changed

.phpstan-baseline.8.2-8.3.php

Lines changed: 578 additions & 0 deletions
Large diffs are not rendered by default.

.phpstan-baseline.8.4.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php declare(strict_types = 1);
2+
3+
if (preg_match('/^8\.4\./', PHP_VERSION) !== 1) {
4+
return ['parameters' => ['ignoreErrors' => []]];
5+
}
6+
7+
/*
8+
* The following error will occur only on PHP 8.4.
9+
* Unfortunately, it is not possible to ignore it using a @phpstan-ignore, so we have to handle it here.
10+
*/
11+
12+
$ignoreErrors = [];
13+
14+
$ignoreErrors[] = [
15+
'message' => '#^Function openssl_pkey_get_details is unsafe to use\\. It can return FALSE instead of throwing an exception\\. Please add \'use function Safe\\\\openssl_pkey_get_details;\' at the beginning of the file to use the variant provided by the \'thecodingmachine/safe\' library\\.$#',
16+
'identifier' => 'theCodingMachineSafe.function',
17+
'count' => 1,
18+
'path' => __DIR__ . '/src/Glpi/OAuth/Server.php',
19+
];
20+
21+
return ['parameters' => ['ignoreErrors' => $ignoreErrors]];

.phpstan-baseline.php

Lines changed: 8067 additions & 2481 deletions
Large diffs are not rendered by default.

ajax/2fa.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
* ---------------------------------------------------------------------
3434
*/
3535

36+
use function Safe\json_encode;
37+
3638
if (isset($_POST['regenerate_backup_codes'])) {
3739
$totp = new \Glpi\Security\TOTPManager();
3840
$codes = $totp->regenerateBackupCodes(Session::getLoginUserID());

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
"symfony/serializer": "^7.1",
9595
"tecnickcom/tc-lib-barcode": "^2.4",
9696
"tecnickcom/tcpdf": "^6.9",
97+
"thecodingmachine/safe": "^3.1",
9798
"thenetworg/oauth2-azure": "^2.2",
9899
"twig/markdown-extra": "^3.20",
99100
"twig/string-extra": "^3.20",
@@ -122,7 +123,8 @@
122123
"symfony/stopwatch": "^6.4",
123124
"symfony/twig-bundle": "^6.4",
124125
"symfony/var-dumper": "^6.4",
125-
"symfony/web-profiler-bundle": "^6.4"
126+
"symfony/web-profiler-bundle": "^6.4",
127+
"thecodingmachine/phpstan-safe-rule": "^1.4"
126128
},
127129
"provide": {
128130
"ext-sodium": "*"

composer.lock

Lines changed: 198 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpstan.neon.dist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
includes:
22
- .phpstan-baseline.php
3+
- .phpstan-baseline.8.2-8.3.php
4+
- .phpstan-baseline.8.4.php
35

46
parameters:
57
level: 4

0 commit comments

Comments
 (0)