glpi-project/phpstan-glpi
Composer 安装命令:
composer require glpi-project/phpstan-glpi
包简介
PHPStan rules for GLPI.
README 文档
README
This repository provides a PHPStan extension that can be used in both GLPI and GLPI plugins.
Installation
To install this PHPStan extension, run the composer require --dev glpi-project/phpstan-glpi.
To make this extension automatically enabled by PHPStan, you can also install the phpstan/extension-installer library,
otherwise you will need to add it in you PHPStan configuration file in the includes section:
includes: - vendor/glpi-project/phpstan-glpi/rules.neon
See https://phpstan.org/user-guide/extension-library#installing-extensions for more information.
Configuration
The PHPStan configuration depends on your GLPI version.
If your plugin is located in either the plugins or marketplace directory of GLPI,
you can use the following configuration file example:
parameters: level: 0 paths: - ajax - front - inc # or `src` if your PHP class files are in the `src` directory - hook.php - setup.php scanDirectories: - ../../inc - ../../src bootstrapFiles: - ../../stubs/glpi_constants.php - ../../vendor/autoload.php
The GLPI path and version should be detected automatically, but you can specify them in the parameters section of your PHPStan configuration:
parameters: glpi: glpiPath: "/path/to/glpi" glpiVersion: "11.0.0"
See https://phpstan.org/config-reference fore more information about the PHPStan configuration options.
Analyser improvements
This extension will help PHPStan to resolve the GLPI global variables types.
For instance, it will indicate that the global $DB; variable is an instance of the DBmysql class,
so PHPStan will be able to detected bad method calls, deprecated methods usages, ...
Rules
ForbidDynamicInstantiationRule
Since GLPI 11.0.
Instantiating an object from an unrestricted dynamic string is unsecure. Indeed, it can lead to unexpected code execution and has already been a source of security issues in GLPI.
Before instantiating an object, a check must be done to validate that the variable contains an expected class string.
$class = $_GET['itemtype']; $object = new $class(); // unsafe if (is_a($class, CommonDBTM::class, true)) { $object = new $class(); // safe }
If the treatPhpDocTypesAsCertain PHPStan parameter is not set to false, a variable with a specific class-string
type will be considered safe.
class MyClass { /** * @var class-string<\CommonDBTM> $class */ public function doSomething(string $class): void { $object = new $class(); // safe // ... } }
ForbidExitRule
Since GLPI 11.0.
Since the introduction of the Symfony framework in GLPI 11.0, the usage of exit()/die() instructions is discouraged.
Indeed, they prevents the execution of post-request/post-command routines, and this can result in unexpected behaviours.
ForbidHttpResponseCodeRule
Since GLPI 11.0.
Due to a PHP bug (see https://bugs.php.net/bug.php?id=81451), the usage of the http_response_code() function, to
define the response code, may produce unexpected results, depending on the server environment.
Therefore, its usage is discouraged.
ForbidHardCodedRightNameRule
Since GLPI 12.0.
In the past, there have been issues where rights management was not handled correctly at the controller level due to the use of an obsolete hardcoded string. To avoid this type of problem, starting with GLPI 12, the use of a hardcoded string, as the first argument (module) of Session::checkRight(), Session::checkRightsOr(),
Session::haveRight(), Session::haveRightsAnd(), or Session::haveRightsOr(), will be considered an error and must be replaced with the $rightname property of the appropriate class.
Session::checkRight('computer', READ); // wrong Session::checkRight(Computer::$rightname, READ); // correct
MissingGlobalVarTypeRule
Since GLPI 10.0.
By default, PHPStan is not able to detect the global variables types, and is therefore not able to detect any issue related to their usage. This extension will resolve the type of GLPI global variables, but cannot resolve your plugin specific global variables. To get around this limitation, we recommend that you declare each global variable type with a PHPDoc tag.
/** @var \Migration $migration */ global migration;
glpi-project/phpstan-glpi 适用场景与选型建议
glpi-project/phpstan-glpi 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 142.27k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 06 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 glpi-project/phpstan-glpi 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 glpi-project/phpstan-glpi 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 142.27k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 20
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-06-24