Skip to content

Commit df0445e

Browse files
committed
Centralize existing rules
1 parent 55d34cb commit df0445e

34 files changed

+5401
-0
lines changed

.gitattributes

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/.github/ export-ignore
2+
/tests/ export-ignore
3+
/.gitattributes export-ignore
4+
/.gitignore export-ignore
5+
/.php-cs-fixer.dist.php export-ignore
6+
/phpstan.neon export-ignore
7+
/phpunit.xml.dist export-ignore

.github/dependabot.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
version: 2
2+
3+
updates:
4+
- package-ecosystem: "github-actions"
5+
directory: "/"
6+
schedule:
7+
interval: "weekly"
8+
9+
- package-ecosystem: "composer"
10+
directory: "/"
11+
schedule:
12+
interval: "monthly"
13+
versioning-strategy: "increase"
14+
groups:
15+
dev-dependencies:
16+
dependency-type: "development"
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: "Continuous integration"
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
concurrency:
10+
group: "${{ github.workflow }}-${{ github.ref }}"
11+
cancel-in-progress: true
12+
13+
jobs:
14+
continuous-integration:
15+
name: "Check with PHP ${{ matrix.php-version }}"
16+
runs-on: "ubuntu-latest"
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
include:
21+
- { php-version: "7.4" }
22+
- { php-version: "8.4" }
23+
steps:
24+
- name: "Checkout"
25+
uses: "actions/checkout@v4"
26+
27+
- name: "Setup PHP"
28+
uses: "shivammathur/setup-php@v2"
29+
with:
30+
php-version: "${{ matrix.php-version }}"
31+
tools: "composer, cs2pr"
32+
33+
# Install dependencies
34+
- name: "Get cache variables"
35+
id: "cache-variables"
36+
run: |
37+
echo "composer=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
38+
- name: "Cache dependencies"
39+
uses: actions/cache@v4
40+
with:
41+
path: "${{ steps.cache-variables.outputs.composer }}"
42+
key: "dependencies-${{ matrix.php-version }}-${{ hashFiles('composer.lock') }}"
43+
restore-keys: |
44+
dependencies-${{ matrix.php-version }}-
45+
dependencies-
46+
- name: "Force used PHP version"
47+
run: |
48+
composer config --unset platform.php --ansi
49+
composer require "php:>=${{ matrix.php-version }}" --ansi --ignore-platform-req=php+ --no-install --no-scripts
50+
- name: "Install and build dependencies"
51+
run: |
52+
composer install --ansi --ignore-platform-req=php+ --no-interaction --no-progress
53+
54+
# Lint
55+
- name: "Validate composer config"
56+
if: ${{ !cancelled() }}
57+
run: |
58+
composer validate --strict
59+
- name: "PHP Parallel Lint"
60+
if: ${{ !cancelled() }}
61+
run: |
62+
vendor/bin/parallel-lint --exclude ./.git/ --exclude ./vendor/ --checkstyle . | cs2pr
63+
- name: "PHP CS Fixer"
64+
if: ${{ !cancelled() }}
65+
run: |
66+
PHP_CS_FIXER_IGNORE_ENV=1 vendor/bin/php-cs-fixer fix --dry-run --format=checkstyle | cs2pr
67+
- name: "PHPStan"
68+
if: ${{ !cancelled() }}
69+
run: |
70+
vendor/bin/phpstan analyse --error-format=checkstyle | cs2pr
71+
72+
# Test
73+
- name: "PHPUnit"
74+
if: ${{ !cancelled() }}
75+
run: |
76+
vendor/bin/phpunit

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/vendor/
2+
.composer.lock

.php-cs-fixer.dist.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
$finder = (new PhpCsFixer\Finder())
4+
->in(__DIR__)
5+
;
6+
7+
return (new PhpCsFixer\Config())
8+
->setParallelConfig(PhpCsFixer\Runner\Parallel\ParallelConfigFactory::detect())
9+
->setRiskyAllowed(true)
10+
->setRules([
11+
'@PER-CS2.0' => true,
12+
'@PHP84Migration' => true,
13+
'declare_strict_types' => true,
14+
'no_unused_imports' => true
15+
])
16+
->setFinder($finder)
17+
;

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# PHPStan GLPI extension
2+
3+
This repository provides a PHPStan extension that can be used in both GLPI and GLPI plugins.
4+
5+
## Installation
6+
7+
To install this PHPStan extension, run the `composer require --dev glpi-project/phpstan-glpi`.
8+
9+
The GLPI version should be detected automatically, but you can specify it in your PHPStan configuration:
10+
```yaml
11+
parameters:
12+
glpi:
13+
glpiVersion: "11.0"
14+
```
15+
16+
## Rules
17+
18+
### `ForbidExitRule`
19+
20+
> Since GLPI 11.0.
21+
22+
Since the introduction of the Symfony framework in GLPI 11.0, the usage of `exit()`/`die()` instructions is discouraged.
23+
Indeed, they prevents the execution of post-request/post-command routines, and this can result in unexpected behaviours.
24+
25+
### `ForbidHttpResponseCodeRule`
26+
27+
> Since GLPI 11.0.
28+
29+
Due to a PHP bug (see https://bugs.php.net/bug.php?id=81451), the usage of the `http_response_code()` function, to
30+
define the response code, may produce unexpected results, depending on the server environment.
31+
Therefore, its usage is discouraged.
32+
33+
### `MissingGlobalVarTypeRule`
34+
35+
> Since GLPI 10.0.
36+
37+
By default, PHPStan is not able to detect the global variables types, and is therefore not able to detect any issue
38+
related to their usage. To get around this limitation, we recommend that you declare each global variable type with
39+
a PHPDoc tag.
40+
```php
41+
/** @var \DBmysql $DB */
42+
global $DB;
43+
```

composer.json

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"name": "glpi-project/phpstan-glpi",
3+
"type": "phpstan-extension",
4+
"description": "PHPStan rules for GLPI.",
5+
"license": [
6+
"MIT"
7+
],
8+
"require": {
9+
"php": ">=7.4",
10+
"phpstan/phpstan": "^2.1"
11+
},
12+
"require-dev": {
13+
"friendsofphp/php-cs-fixer": "^3.75",
14+
"php-parallel-lint/php-parallel-lint": "^1.4",
15+
"phpstan/phpstan-phpunit": "^2.0",
16+
"phpunit/phpunit": "^9.6"
17+
},
18+
"config": {
19+
"optimize-autoloader": true,
20+
"platform": {
21+
"php": "7.4.99"
22+
},
23+
"sort-packages": true
24+
},
25+
"extra": {
26+
"phpstan": {
27+
"includes": [
28+
"rules.neon"
29+
]
30+
}
31+
},
32+
"autoload": {
33+
"psr-4": {
34+
"PHPStanGlpi\\": "src/"
35+
}
36+
},
37+
"autoload-dev": {
38+
"classmap": [
39+
"tests/"
40+
],
41+
"psr-4": {
42+
"PHPStanGlpi\\Tests\\": "tests/"
43+
}
44+
},
45+
"minimum-stability": "dev",
46+
"prefer-stable": true
47+
}

0 commit comments

Comments
 (0)