-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4fb5aea
commit 6b6e5cc
Showing
60 changed files
with
611 additions
and
1,472 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# These are supported funding model platforms | ||
github: tomasvotruba |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
name: Code Analysis | ||
|
||
on: | ||
pull_request: null | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
code_analysis: | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
actions: | ||
- | ||
name: 'PHPStan' | ||
run: composer phpstan --ansi | ||
|
||
- | ||
name: 'Composer Validate' | ||
run: composer validate --ansi | ||
|
||
- | ||
name: 'Coding Standard' | ||
run: composer fix-cs --ansi | ||
|
||
- | ||
name: 'Check Commented Code' | ||
run: vendor/bin/easy-ci check-commented-code src --ansi | ||
|
||
- | ||
name: 'Check Active Classes' | ||
run: vendor/bin/class-leak check src --ansi | ||
|
||
name: ${{ matrix.actions.name }} | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
# see https://github.com/shivammathur/setup-php | ||
- uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: 8.2 | ||
coverage: none | ||
|
||
# composer install cache - https://github.com/ramsey/composer-install | ||
- uses: "ramsey/composer-install@v2" | ||
|
||
- run: ${{ matrix.actions.run }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
name: Rector | ||
|
||
on: | ||
pull_request: null | ||
|
||
jobs: | ||
rector: | ||
# run only on core developers with access | ||
if: github.event.pull_request.head.repo.full_name == github.repository | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- | ||
uses: actions/checkout@v2 | ||
with: | ||
token: ${{ secrets.ACCESS_TOKEN }} | ||
|
||
- | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: 8.2 | ||
|
||
- uses: "ramsey/composer-install@v1" | ||
|
||
## First run Rector - here can't be --dry-run !!! it would stop the job with it and not commit anything in the future | ||
- run: vendor/bin/rector process ${{ matrix.directories }} --ansi | ||
|
||
- run: vendor/bin/ecs check --fix --ansi | ||
|
||
# see https://github.com/EndBug/add-and-commit | ||
- | ||
# commit only to core contributors who have repository access | ||
if: github.event.pull_request.head.repo.full_name == github.repository | ||
uses: EndBug/[email protected] | ||
with: | ||
# The arguments for the `git add` command (see the paragraph below for more info) | ||
add: . | ||
message: "[ci-review] Rector Rectify" | ||
author_name: "GitHub Action" | ||
author_email: "[email protected]" | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,4 @@ | ||
composer.lock | ||
/vendor | ||
|
||
.phpunit.cache | ||
|
||
|
||
bootstrap/cache/* | ||
!bootstrap/cache/.gitkeep | ||
|
||
storage/* | ||
|
||
# avoid commiting scoper phar file | ||
php-scoper.phar | ||
bodyscan-log.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,75 @@ | ||
# Class Leak | ||
# PHPStan Bodyscan | ||
|
||
[![Downloads total](https://img.shields.io/packagist/dt/tomasvotruba/class-leak.svg?style=flat-square)](https://packagist.org/packages/tomasvotruba/class-leak/stats) | ||
[![Downloads total](https://img.shields.io/packagist/dt/tomasvotruba/phpstan-bodyscan.svg?style=flat-square)](https://packagist.org/packages/tomasvotruba/phpstan-bodyscan/stats) | ||
|
||
Do you want to get quick glimpse of new project code quality? | ||
|
||
Get error count for each PHPStan level! | ||
|
||
Find leaking classes that you never use... and get rid of them. | ||
|
||
## Install | ||
|
||
```bash | ||
composer require tomasvotruba/class-leak --dev | ||
composer require tomasvotruba/phpstan-bodyscan --dev | ||
``` | ||
|
||
## Usage | ||
|
||
Pass directories you want to check: | ||
Run tool in your project. It will take some time, as it will run PHPStan for each level. | ||
|
||
|
||
```bash | ||
vendor/bin/class-leak check bin src | ||
vendor/bin/phpstan-bodyscan | ||
``` | ||
|
||
Make sure to exclude `/tests` directories, to keep reporting classes that are used in tests, but never used in the code-base. | ||
|
||
<br> | ||
↓ | ||
|
||
Many types are excluded by default, as they're collected by framework magic, e.g. console command classes. To exclude another class, e.g. your interface collector, use `--skip-type`: | ||
To get errors count per level: | ||
|
||
```bash | ||
vendor/bin/class-leak check bin src --skip-type="App\\Contract\\SomeInterface" | ||
+-------+-------------+ | ||
| Level | Error count | | ||
+-------+-------------+ | ||
| 0 | 0 | | ||
| 1 | 35 | | ||
| 2 | 59 | | ||
| 3 | 93 | | ||
| 4 | 120 | | ||
| 5 | 125 | | ||
| 6 | 253 | | ||
| 7 | 350 | | ||
| 8 | 359 | | ||
+-------+-------------+ | ||
``` | ||
|
||
What if your classes do no implement any type? Use `--skip-suffix` instead: | ||
<br> | ||
|
||
### Limit level count | ||
|
||
Are you interested only in a few levels? You can limit ranges by the options: | ||
|
||
```bash | ||
vendor/bin/class-leak check bin src --skip-suffix "Controller" | ||
vendor/bin/phpstan-bodyscan run --min-level 0 --max-level 3 | ||
``` | ||
|
||
If you want to skip classes that use a specific attribute or have methods that use a specific attribute, use `--skip-attribute`: | ||
<br> | ||
|
||
### Load env file | ||
|
||
Some projects need to load `.env` file to run PHPStan. You can do it like this: | ||
|
||
```bash | ||
vendor/bin/class-leak check bin src --skip-attribute "Symfony\\Component\\HttpKernel\\Attribute\\AsController" | ||
vendor/bin/phpstan-bodyscan run --env-file some-parameters.env | ||
``` | ||
|
||
<br> | ||
|
||
### Debugging | ||
|
||
Running PHPStan on a new project you don't know might crash. To save data from finished levels, we dump them to the `bodyscan-log.txt` file. | ||
|
||
If the run crashes for any reason, the PHPStan error output is also dumped to the same file. | ||
|
||
<br> | ||
|
||
Happy coding! |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
|
||
require __DIR__ . '/phpstan-bodyscan.php'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Symfony\Component\Console\Application; | ||
use Symfony\Component\Console\Input\ArgvInput; | ||
use Symfony\Component\Console\Input\ArrayInput; | ||
use Symfony\Component\Console\Output\ConsoleOutput; | ||
use Symfony\Component\Console\Style\SymfonyStyle; | ||
use TomasVotruba\PHPStanBodyscan\Command\RunCommand; | ||
use TomasVotruba\PHPStanBodyscan\Process\AnalyseProcessFactory; | ||
|
||
if (file_exists(__DIR__ . '/../../../../vendor/autoload.php')) { | ||
// project's autoload | ||
require_once __DIR__ . '/../../../../vendor/autoload.php'; | ||
} else { | ||
// B. local repository | ||
require_once __DIR__ . '/../vendor/autoload.php'; | ||
} | ||
|
||
$symfonyStyle = new SymfonyStyle(new ArrayInput([]), new ConsoleOutput()); | ||
$runCommand = new RunCommand($symfonyStyle, new AnalyseProcessFactory()); | ||
|
||
$application = new Application(); | ||
$application->add($runCommand); | ||
$application->setDefaultCommand('run'); | ||
|
||
// hide default commands | ||
$application->get('completion') | ||
->setHidden(); | ||
$application->get('help') | ||
->setHidden(); | ||
$application->get('list') | ||
->setHidden(); | ||
|
||
$exitCode = $application->run(new ArgvInput(), new ConsoleOutput()); | ||
exit($exitCode); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,44 @@ | ||
{ | ||
"name": "tomasvotruba/class-leak", | ||
"description": "Detect leaking classes", | ||
"name": "tomasvotruba/phpstan-bodyscan", | ||
"description": "Get error count for each PHPStan level", | ||
"license": "MIT", | ||
"bin": [ | ||
"bin/class-leak", | ||
"bin/class-leak.php" | ||
"bin/phpstan-bodyscan", | ||
"bin/phpstan-bodyscan.php" | ||
], | ||
"require": { | ||
"php": ">=8.2", | ||
"illuminate/container": "^11.0", | ||
"nette/utils": "^3.2", | ||
"nikic/php-parser": "^4.19", | ||
"symfony/console": "^6.4", | ||
"symfony/finder": "^6.4", | ||
"symfony/process": "^7.0", | ||
"webmozart/assert": "^1.11" | ||
}, | ||
"require-dev": { | ||
"phpstan/extension-installer": "^1.2", | ||
"phpstan/phpstan": "^1.10.57", | ||
"phpunit/phpunit": "^10.5", | ||
"phpstan/extension-installer": "^1.3", | ||
"phpstan/phpstan": "^1.10", | ||
"rector/rector": "^1.0", | ||
"symplify/easy-ci": "^12.1", | ||
"symplify/easy-coding-standard": "^12.1", | ||
"symplify/phpstan-extensions": "^11.2", | ||
"tomasvotruba/unused-public": "^0.2", | ||
"symplify/phpstan-rules": "^12.4", | ||
"tomasvotruba/class-leak": "^0.2.13", | ||
"tomasvotruba/type-coverage": "^0.2.8", | ||
"tomasvotruba/unused-public": "^0.3.8", | ||
"tracy/tracy": "^2.10" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"TomasVotruba\\ClassLeak\\": "src" | ||
"TomasVotruba\\PHPStanBodyscan\\": "src" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"TomasVotruba\\ClassLeak\\Tests\\": "tests" | ||
} | ||
}, | ||
"replace": { | ||
"symfony/polyfill-ctype": "*", | ||
"symfony/polyfill-intl-grapheme": "*", | ||
"symfony/polyfill-intl-normalizer": "*", | ||
"symfony/polyfill-mbstring": "*" | ||
}, | ||
"config": { | ||
"sort-packages": true, | ||
"platform-check": false, | ||
"allow-plugins": { | ||
"phpstan/extension-installer": true | ||
} | ||
}, | ||
"scripts": { | ||
"check-cs": "vendor/bin/ecs check --ansi", | ||
"fix-cs": "vendor/bin/ecs check --fix --ansi", | ||
"phpstan": "vendor/bin/phpstan analyse --ansi --error-format symplify", | ||
"phpstan": "vendor/bin/phpstan analyse --ansi", | ||
"rector": "vendor/bin/rector process --dry-run --ansi" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
use Symplify\CodingStandard\Fixer\LineLength\LineLengthFixer; | ||
|
||
use Symplify\EasyCodingStandard\Config\ECSConfig; | ||
|
||
return ECSConfig::configure() | ||
->withPaths([ | ||
__DIR__ . '/bin', | ||
__DIR__ . '/src', | ||
__DIR__ . '/tests', | ||
]) | ||
->withRules([ | ||
LineLengthFixer::class, | ||
]) | ||
->withPreparedSets(psr12: true, common: true, symplify: true); |
Oops, something went wrong.