mirror of
https://github.com/pluginsGLPI/example.git
synced 2025-10-13 20:24:34 +02:00
Fix(CI): phpstan (#109)
This commit is contained in:
9
hook.php
9
hook.php
@@ -624,12 +624,11 @@ function plugin_example_uninstall()
|
|||||||
ProfileRight::deleteProfileRights([Example::$rightname]);
|
ProfileRight::deleteProfileRights([Example::$rightname]);
|
||||||
|
|
||||||
$notif = new Notification();
|
$notif = new Notification();
|
||||||
$options = ['itemtype' => 'Ticket',
|
$notif->deleteByCriteria([
|
||||||
|
'itemtype' => 'Ticket',
|
||||||
'event' => 'plugin_example',
|
'event' => 'plugin_example',
|
||||||
'FIELDS' => 'id'];
|
'FIELDS' => 'id',
|
||||||
foreach ($DB->request('glpi_notifications', $options) as $data) {
|
]);
|
||||||
$notif->delete($data);
|
|
||||||
}
|
|
||||||
// Old version tables
|
// Old version tables
|
||||||
if ($DB->tableExists('glpi_dropdown_plugin_example')) {
|
if ($DB->tableExists('glpi_dropdown_plugin_example')) {
|
||||||
$query = 'DROP TABLE `glpi_dropdown_plugin_example`';
|
$query = 'DROP TABLE `glpi_dropdown_plugin_example`';
|
||||||
|
15
phpstan.neon
15
phpstan.neon
@@ -1,6 +1,9 @@
|
|||||||
|
includes:
|
||||||
|
- ../../vendor/glpi-project/phpstan-glpi/extension.neon
|
||||||
|
- ../../vendor/phpstan/phpstan-deprecation-rules/rules.neon
|
||||||
|
- ../../vendor/thecodingmachine/phpstan-safe-rule/phpstan-safe-rule.neon
|
||||||
|
|
||||||
parameters:
|
parameters:
|
||||||
parallel:
|
|
||||||
maximumNumberOfProcesses: 2
|
|
||||||
level: 5
|
level: 5
|
||||||
paths:
|
paths:
|
||||||
- front
|
- front
|
||||||
@@ -10,10 +13,12 @@ parameters:
|
|||||||
- setup.php
|
- setup.php
|
||||||
- stat.php
|
- stat.php
|
||||||
scanDirectories:
|
scanDirectories:
|
||||||
- ../../inc
|
|
||||||
- ../../src
|
- ../../src
|
||||||
- ../../front
|
|
||||||
bootstrapFiles:
|
bootstrapFiles:
|
||||||
- ../../stubs/glpi_constants.php
|
- ../../stubs/glpi_constants.php
|
||||||
- ../../vendor/autoload.php
|
- ../../vendor/autoload.php
|
||||||
|
- setup.php
|
||||||
|
treatPhpDocTypesAsCertain: false
|
||||||
|
ignoreErrors:
|
||||||
|
- message: "#.*always true#"
|
||||||
|
- message: "#Unreachable statement#"
|
||||||
|
@@ -28,6 +28,8 @@
|
|||||||
* -------------------------------------------------------------------------
|
* -------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use function Safe\define;
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
// Original Author of file:
|
// Original Author of file:
|
||||||
// Purpose of file:
|
// Purpose of file:
|
||||||
|
@@ -39,6 +39,8 @@ use GlpiPlugin\Example\Profile;
|
|||||||
use GlpiPlugin\Example\RuleTestCollection;
|
use GlpiPlugin\Example\RuleTestCollection;
|
||||||
use GlpiPlugin\Example\Showtabitem;
|
use GlpiPlugin\Example\Showtabitem;
|
||||||
|
|
||||||
|
use function Safe\define;
|
||||||
|
|
||||||
define('PLUGIN_EXAMPLE_VERSION', '0.1.0');
|
define('PLUGIN_EXAMPLE_VERSION', '0.1.0');
|
||||||
|
|
||||||
// Minimal GLPI version, inclusive
|
// Minimal GLPI version, inclusive
|
||||||
|
@@ -57,8 +57,17 @@
|
|||||||
|
|
||||||
namespace GlpiPlugin\Example;
|
namespace GlpiPlugin\Example;
|
||||||
|
|
||||||
|
use Glpi\Exception\Http\NotFoundHttpException;
|
||||||
|
use Glpi\Exception\Http\HttpException;
|
||||||
use Document as GlpiDocument;
|
use Document as GlpiDocument;
|
||||||
|
|
||||||
|
use function Safe\filemtime;
|
||||||
|
use function Safe\filesize;
|
||||||
|
use function Safe\fopen;
|
||||||
|
use function Safe\fread;
|
||||||
|
use function Safe\preg_match;
|
||||||
|
use function Safe\set_time_limit;
|
||||||
|
|
||||||
class Document extends GlpiDocument
|
class Document extends GlpiDocument
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@@ -142,8 +151,7 @@ class Document extends GlpiDocument
|
|||||||
|
|
||||||
// Ensure the file exists
|
// Ensure the file exists
|
||||||
if (!file_exists($streamSource) || !is_file($streamSource)) {
|
if (!file_exists($streamSource) || !is_file($streamSource)) {
|
||||||
header('HTTP/1.0 404 Not Found');
|
throw new NotFoundHttpException();
|
||||||
exit(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Download range defaults to the full file
|
// Download range defaults to the full file
|
||||||
@@ -157,8 +165,7 @@ class Document extends GlpiDocument
|
|||||||
// Open the file
|
// Open the file
|
||||||
$fileHandle = @fopen($streamSource, 'rb');
|
$fileHandle = @fopen($streamSource, 'rb');
|
||||||
if (!$fileHandle) {
|
if (!$fileHandle) {
|
||||||
header('HTTP/1.0 500 Internal Server Error');
|
throw new HttpException(500, 'Internal Server Error');
|
||||||
exit(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// set range if specified by the client
|
// set range if specified by the client
|
||||||
@@ -174,8 +181,7 @@ class Document extends GlpiDocument
|
|||||||
// seek to the begining of the range
|
// seek to the begining of the range
|
||||||
$currentPosition = $begin;
|
$currentPosition = $begin;
|
||||||
if (fseek($fileHandle, $begin, SEEK_SET) < 0) {
|
if (fseek($fileHandle, $begin, SEEK_SET) < 0) {
|
||||||
header('HTTP/1.0 500 Internal Server Error');
|
throw new HttpException(500, 'Internal Server Error');
|
||||||
exit(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// send headers to ensure the client is able to detect a corrupted download
|
// send headers to ensure the client is able to detect a corrupted download
|
||||||
@@ -206,9 +212,8 @@ class Document extends GlpiDocument
|
|||||||
// allow a few seconds to send a few KB.
|
// allow a few seconds to send a few KB.
|
||||||
set_time_limit(10);
|
set_time_limit(10);
|
||||||
$content = fread($fileHandle, min(1024 * 16, $end - $currentPosition + 1));
|
$content = fread($fileHandle, min(1024 * 16, $end - $currentPosition + 1));
|
||||||
if ($content === false) {
|
if (empty($content)) {
|
||||||
header('HTTP/1.0 500 Internal Server Error', true); // Replace previously sent headers
|
throw new HttpException(500, 'Internal Server Error');
|
||||||
exit(0);
|
|
||||||
} else {
|
} else {
|
||||||
print $content;
|
print $content;
|
||||||
}
|
}
|
||||||
@@ -217,6 +222,6 @@ class Document extends GlpiDocument
|
|||||||
}
|
}
|
||||||
|
|
||||||
// End now to prevent any unwanted bytes
|
// End now to prevent any unwanted bytes
|
||||||
exit(0);
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -49,6 +49,8 @@ use Preference;
|
|||||||
use Session;
|
use Session;
|
||||||
use Supplier;
|
use Supplier;
|
||||||
|
|
||||||
|
use function Safe\strtotime;
|
||||||
|
|
||||||
// Class of the defined type
|
// Class of the defined type
|
||||||
class Example extends CommonDBTM
|
class Example extends CommonDBTM
|
||||||
{
|
{
|
||||||
|
2
stat.php
2
stat.php
@@ -28,6 +28,8 @@
|
|||||||
* -------------------------------------------------------------------------
|
* -------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use function Safe\define;
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
// Original Author of file:
|
// Original Author of file:
|
||||||
// Purpose of file:
|
// Purpose of file:
|
||||||
|
Reference in New Issue
Block a user