Skip to content

Commit c21b23e

Browse files
authored
Fix(CI): phpstan (#109)
1 parent 69426cd commit c21b23e

File tree

7 files changed

+38
-21
lines changed

7 files changed

+38
-21
lines changed

hook.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -624,12 +624,11 @@ function plugin_example_uninstall()
624624
ProfileRight::deleteProfileRights([Example::$rightname]);
625625

626626
$notif = new Notification();
627-
$options = ['itemtype' => 'Ticket',
628-
'event' => 'plugin_example',
629-
'FIELDS' => 'id'];
630-
foreach ($DB->request('glpi_notifications', $options) as $data) {
631-
$notif->delete($data);
632-
}
627+
$notif->deleteByCriteria([
628+
'itemtype' => 'Ticket',
629+
'event' => 'plugin_example',
630+
'FIELDS' => 'id',
631+
]);
633632
// Old version tables
634633
if ($DB->tableExists('glpi_dropdown_plugin_example')) {
635634
$query = 'DROP TABLE `glpi_dropdown_plugin_example`';

phpstan.neon

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
includes:
2+
- ../../vendor/glpi-project/phpstan-glpi/extension.neon
3+
- ../../vendor/phpstan/phpstan-deprecation-rules/rules.neon
4+
- ../../vendor/thecodingmachine/phpstan-safe-rule/phpstan-safe-rule.neon
5+
16
parameters:
2-
parallel:
3-
maximumNumberOfProcesses: 2
47
level: 5
58
paths:
69
- front
@@ -10,10 +13,12 @@ parameters:
1013
- setup.php
1114
- stat.php
1215
scanDirectories:
13-
- ../../inc
1416
- ../../src
15-
- ../../front
1617
bootstrapFiles:
1718
- ../../stubs/glpi_constants.php
1819
- ../../vendor/autoload.php
19-
20+
- setup.php
21+
treatPhpDocTypesAsCertain: false
22+
ignoreErrors:
23+
- message: "#.*always true#"
24+
- message: "#Unreachable statement#"

report.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
* -------------------------------------------------------------------------
2929
*/
3030

31+
use function Safe\define;
32+
3133
// ----------------------------------------------------------------------
3234
// Original Author of file:
3335
// Purpose of file:

setup.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
use GlpiPlugin\Example\RuleTestCollection;
4040
use GlpiPlugin\Example\Showtabitem;
4141

42+
use function Safe\define;
43+
4244
define('PLUGIN_EXAMPLE_VERSION', '0.1.0');
4345

4446
// Minimal GLPI version, inclusive

src/Document.php

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,17 @@
5757

5858
namespace GlpiPlugin\Example;
5959

60+
use Glpi\Exception\Http\NotFoundHttpException;
61+
use Glpi\Exception\Http\HttpException;
6062
use Document as GlpiDocument;
6163

64+
use function Safe\filemtime;
65+
use function Safe\filesize;
66+
use function Safe\fopen;
67+
use function Safe\fread;
68+
use function Safe\preg_match;
69+
use function Safe\set_time_limit;
70+
6271
class Document extends GlpiDocument
6372
{
6473
/**
@@ -142,8 +151,7 @@ protected function sendFile()
142151

143152
// Ensure the file exists
144153
if (!file_exists($streamSource) || !is_file($streamSource)) {
145-
header('HTTP/1.0 404 Not Found');
146-
exit(0);
154+
throw new NotFoundHttpException();
147155
}
148156

149157
// Download range defaults to the full file
@@ -157,8 +165,7 @@ protected function sendFile()
157165
// Open the file
158166
$fileHandle = @fopen($streamSource, 'rb');
159167
if (!$fileHandle) {
160-
header('HTTP/1.0 500 Internal Server Error');
161-
exit(0);
168+
throw new HttpException(500, 'Internal Server Error');
162169
}
163170

164171
// set range if specified by the client
@@ -174,8 +181,7 @@ protected function sendFile()
174181
// seek to the begining of the range
175182
$currentPosition = $begin;
176183
if (fseek($fileHandle, $begin, SEEK_SET) < 0) {
177-
header('HTTP/1.0 500 Internal Server Error');
178-
exit(0);
184+
throw new HttpException(500, 'Internal Server Error');
179185
}
180186

181187
// send headers to ensure the client is able to detect a corrupted download
@@ -206,9 +212,8 @@ protected function sendFile()
206212
// allow a few seconds to send a few KB.
207213
set_time_limit(10);
208214
$content = fread($fileHandle, min(1024 * 16, $end - $currentPosition + 1));
209-
if ($content === false) {
210-
header('HTTP/1.0 500 Internal Server Error', true); // Replace previously sent headers
211-
exit(0);
215+
if (empty($content)) {
216+
throw new HttpException(500, 'Internal Server Error');
212217
} else {
213218
print $content;
214219
}
@@ -217,6 +222,6 @@ protected function sendFile()
217222
}
218223

219224
// End now to prevent any unwanted bytes
220-
exit(0);
225+
return;
221226
}
222227
}

src/Example.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
use Session;
5050
use Supplier;
5151

52+
use function Safe\strtotime;
53+
5254
// Class of the defined type
5355
class Example extends CommonDBTM
5456
{

stat.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
* -------------------------------------------------------------------------
2929
*/
3030

31+
use function Safe\define;
32+
3133
// ----------------------------------------------------------------------
3234
// Original Author of file:
3335
// Purpose of file:

0 commit comments

Comments
 (0)