Skip to content

Commit 1bc5654

Browse files
committed
Initial commit of PHPStan unused class rule.
1 parent 0bb1fd3 commit 1bc5654

23 files changed

+4294
-38
lines changed

.gitignore

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,15 @@
1-
# Cache and logs (Symfony2)
2-
/app/cache/*
3-
/app/logs/*
4-
!app/cache/.gitkeep
5-
!app/logs/.gitkeep
6-
7-
# Email spool folder
8-
/app/spool/*
9-
10-
# Cache, session files and logs (Symfony3)
11-
/var/cache/*
12-
/var/logs/*
13-
/var/sessions/*
14-
!var/cache/.gitkeep
15-
!var/logs/.gitkeep
16-
!var/sessions/.gitkeep
17-
18-
# Logs (Symfony4)
19-
/var/log/*
20-
!var/log/.gitkeep
21-
22-
# Parameters
23-
/app/config/parameters.yml
24-
/app/config/parameters.ini
25-
261
# Managed by Composer
272
/app/bootstrap.php.cache
283
/var/bootstrap.php.cache
294
/bin/*
305
!bin/console
31-
!bin/symfony_requirements
326
/vendor/
337

34-
# Assets and user uploads
35-
/web/bundles/
36-
/web/uploads/
37-
388
# PHPUnit
39-
/app/phpunit.xml
409
/phpunit.xml
4110

4211
# Build data
4312
/build/
4413

4514
# Composer PHAR
4615
/composer.phar
47-
48-
# Backup entities generated with doctrine:generate:entities command
49-
**/Entity/*~
50-
51-
# Embedded web-server pid file
52-
/.web-server-pid

.phpunit.result.cache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"version":1,"defects":{"Xact\\PHPStan\\Tests\\UnusedClassRuleTest::testRule":3},"times":{"Xact\\PHPStan\\Tests\\UnusedClassRuleTest::testRule":1.244}}

.vscode/launch.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
8+
{
9+
"name": "Listen for Xdebug",
10+
"type": "php",
11+
"request": "launch",
12+
"port": 9003,
13+
"log": true
14+
},
15+
{
16+
"name": "Launch currently open script",
17+
"type": "php",
18+
"request": "launch",
19+
"program": "${file}",
20+
"cwd": "${fileDirname}",
21+
"port": 0,
22+
"runtimeArgs": [
23+
"-dxdebug.start_with_request=yes"
24+
],
25+
"env": {
26+
"XDEBUG_MODE": "debug,develop",
27+
"XDEBUG_CONFIG": "client_port=${port}"
28+
}
29+
}
30+
]
31+
}

.vscode/settings.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"intelephense.environment.phpVersion": "8.2.5",
3+
"terminal.integrated.env.linux": {
4+
"PHP_VERSION": "82"
5+
}
6+
}

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2023 X.act Systems
3+
Copyright (c) 2023 X.act Systems and Ian Foulds
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# A collection of PHPStan extensions
2+
3+
This repo contains some useful PHPStan extension for detecting errors in your code. The currently list of rules is:
4+
- ==UnusedClassRule==
5+
6+
## Install
7+
8+
```bash
9+
composer require xactsystems/phpstan-extensions --dev
10+
```
11+
12+
13+
## Usage
14+
15+
With [PHPStan extension installer](https://github.com/phpstan/extension-installer), everything is ready to run.
16+
17+
Otherwise manually enable the extension:
18+
```yaml
19+
# phpstan.neon
20+
include:
21+
'vendor/xactsystems/phpstan-extensions/config/extension.neon'
22+
23+
```
24+
25+
## Rules
26+
### UnusedClassRule
27+
This rule scans for class declarations and use statements. If a class is declared but not used within the scanned source files, an error is generated.
28+
29+
#### Excluding files
30+
You can exclude directories and individual files from being scanned by this rule:
31+
32+
```yaml
33+
# phpstan.neon
34+
parameters:
35+
unused_classes:
36+
- 'src/Entity'
37+
- 'src/Controller'
38+
- 'src/Repositories'
39+
- 'src/MyUnusedClass.php'
40+
```

composer.json

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"name": "xactsystems/phpstan-extensions",
3+
"description": "A collection of PHPStan extensions found useful in our projects.",
4+
"type": "phpstan-extension",
5+
"version": "1.0.0",
6+
"keywords": [
7+
"phpstan",
8+
"static analysis"
9+
],
10+
"repositories": [
11+
{
12+
"type": "path",
13+
"url": "../phpstan-src"
14+
}
15+
],
16+
"require": {
17+
"php": "^7.4 || ^8.0",
18+
"webmozart/assert": "^1.11"
19+
},
20+
"require-dev": {
21+
"phpunit/phpunit": "^9.6",
22+
"xactsystems/phpstan-dev": "dev-master"
23+
},
24+
"license": "MIT",
25+
"autoload": {
26+
"psr-4": {
27+
"Xact\\PHPStan\\": "src/",
28+
"Xact\\PHPStan\\Tests\\": "tests/"
29+
}
30+
},
31+
"scripts": {
32+
},
33+
"authors": [
34+
{
35+
"name": "Ian Foulds",
36+
"email": "ianfoulds@x-act.co.uk"
37+
}
38+
],
39+
"config": {
40+
"allow-plugins": {
41+
"xactsystems/phpstan-dev": true
42+
}
43+
},
44+
"extra": {
45+
"phpstan": {
46+
"includes": [
47+
"config/extension.neon"
48+
]
49+
}
50+
},
51+
"minimum-stability": "dev"
52+
}

0 commit comments

Comments
 (0)