Skip to content

Commit a2c8fe6

Browse files
authored
Automatically detect global variable types
1 parent d40d67e commit a2c8fe6

32 files changed

+696
-4556
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
/vendor/
2-
.composer.lock
2+
.php-cs-fixer.cache
3+
.phpunit.result.cache
4+
composer.lock

README.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,22 @@ parameters:
4545
- ../../stubs/glpi_constants.php
4646
```
4747

48-
The GLPI version should be detected automatically, but you can specify it in the `parameters` section of your PHPStan configuration:
48+
The GLPI path and version should be detected automatically, but you can specify them in the `parameters` section of your PHPStan configuration:
4949
```neon
5050
parameters:
5151
glpi:
52-
glpiVersion: "11.0"
52+
glpiPath: "/path/to/glpi"
53+
glpiVersion: "11.0.0"
5354
```
5455

5556
See https://phpstan.org/config-reference fore more information about the PHPStan configuration options.
5657

58+
## Analyser improvements
59+
60+
This extension will help PHPStan to resolve the GLPI global variables types.
61+
For instance, it will indicate that the `global $DB;` variable is an instance of the `DBmysql` class,
62+
so PHPStan will be able to detected bad method calls, deprecated methods usages, ...
63+
5764
## Rules
5865

5966
### `ForbidDynamicInstantiationRule`
@@ -111,9 +118,10 @@ Therefore, its usage is discouraged.
111118
> Since GLPI 10.0.
112119
113120
By default, PHPStan is not able to detect the global variables types, and is therefore not able to detect any issue
114-
related to their usage. To get around this limitation, we recommend that you declare each global variable type with
115-
a PHPDoc tag.
121+
related to their usage. This extension will resolve the type of GLPI global variables, but cannot resolve your plugin
122+
specific global variables.
123+
To get around this limitation, we recommend that you declare each global variable type with a PHPDoc tag.
116124
```php
117-
/** @var \DBmysql $DB */
118-
global $DB;
125+
/** @var \Migration $migration */
126+
global migration;
119127
```

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
],
88
"require": {
99
"php": ">=7.4",
10-
"phpstan/phpstan": "^2.1"
10+
"phpstan/phpstan": "^2.1",
11+
"symfony/polyfill-php80": "^1.32"
1112
},
1213
"require-dev": {
1314
"friendsofphp/php-cs-fixer": "^3.76",

0 commit comments

Comments
 (0)