Skip to content

Commit 4007202

Browse files
authored
The Dead Code Detector as part of the main PHPStan config (#333)
In #332 I have added the Dead Code Detector but it was using 2 extra config files. Here I move the configuration to the main PHPStan config file and remove the extra configs, less mess 😅 The disadvantage is that the detector will not find the dead code in the test files but I can live with that. It makes little sense anyway I think.
2 parents a24bb8f + e11efa7 commit 4007202

File tree

4 files changed

+12
-36
lines changed

4 files changed

+12
-36
lines changed

.gitattributes

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
phpcs.xml export-ignore
66
phpstan.neon export-ignore
77
phpstan-attributes.php export-ignore
8-
phpstan-dead-code-detector.neon export-ignore
9-
phpstan-dead-code-detector-no-tests.neon export-ignore
108
phpstan-exclude-paths.php export-ignore
119
phpstan-ignore-errors.php export-ignore
1210
phpunit.xml export-ignore

.github/workflows/php.yml

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -143,34 +143,3 @@ jobs:
143143

144144
- name: Run tests
145145
run: composer phpunit
146-
147-
dead-code-detector:
148-
runs-on: ubuntu-latest
149-
150-
strategy:
151-
matrix:
152-
php-version:
153-
- "8.4"
154-
run:
155-
- composer phpstan-dead-code-detector
156-
- composer phpstan-dead-code-detector-no-tests
157-
158-
steps:
159-
- uses: actions/checkout@v4
160-
161-
- name: "Install PHP"
162-
uses: shivammathur/setup-php@v2
163-
with:
164-
coverage: "none"
165-
php-version: "${{ matrix.php-version }}"
166-
167-
- name: PHP info
168-
run: |
169-
php -v
170-
php -m
171-
172-
- name: Install dependencies
173-
run: composer update --no-progress --no-interaction
174-
175-
- name: Run tests
176-
run: ${{ matrix.run }}

composer.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"psr-4": {"Spaze\\PHPStan\\Rules\\Disallowed\\": "src"}
3939
},
4040
"autoload-dev": {
41-
"classmap": ["tests/src"]
41+
"classmap": ["tests"]
4242
},
4343
"scripts": {
4444
"lint": "vendor/bin/parallel-lint --colors src/ tests/",
@@ -50,8 +50,6 @@
5050
"phpcs": "vendor/bin/phpcs src/ tests/",
5151
"cs-fix": "vendor/bin/phpcbf src/ tests/",
5252
"phpstan": "vendor/bin/phpstan --ansi analyse --configuration phpstan.neon",
53-
"phpstan-dead-code-detector": "vendor/bin/phpstan --ansi analyse --configuration phpstan-dead-code-detector.neon",
54-
"phpstan-dead-code-detector-no-tests": "vendor/bin/phpstan --ansi analyse --configuration phpstan-dead-code-detector-no-tests.neon",
5553
"phpunit": "php -d zend.assertions=1 vendor/bin/phpunit --colors=always",
5654
"test": [
5755
"@lint",

phpstan.neon

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,23 @@ parameters:
1919
- tests/src
2020
bootstrapFiles:
2121
- phpstan-attributes.php
22+
ignoreErrors:
23+
-
24+
identifier: shipmonk.deadMethod # Used in extension.neon
25+
paths:
26+
- src/DisallowedSuperglobalFactory.php
27+
- src/DisallowedControlStructureFactory.php
28+
shipmonkDeadCode:
29+
usageExcluders:
30+
tests:
31+
enabled: true
2232

2333
includes:
2434
- phpstan-exclude-paths.php
2535
- phpstan-ignore-errors.php
2636
- vendor/phpstan/phpstan/conf/bleedingEdge.neon
2737
- vendor/phpstan/phpstan-deprecation-rules/rules.neon
38+
- vendor/shipmonk/dead-code-detector/rules.neon
2839
- extension.neon
2940
- disallowed-dangerous-calls.neon
3041
- disallowed-execution-calls.neon

0 commit comments

Comments
 (0)