PhpMetrics
PhpMetrics copied to clipboard
Fix phpstan level-0 and level-1 violations and some bugs
According to roadmap #386, phpstan will be included in v2. I think we can add phpstan by fixing violations level by level.
Here is a list of phpstan violations.
Level-0 violations
- [x] Class
Hal\Violation\ViolationParserdoes not have a constructor and must be instantiated without any parameters. - [x] Access to an undefined property
Hal\Component\Output\ProgressBar::$stream - [x] Access to an undefined property
Hal\Report\Html\Reporter::$sum - [x] Access to an undefined property
Hal\Report\Html\Reporter::$avg - [x] Access to an undefined property
Hal\Report\Html\Reporter::$classes - [x] Access to an undefined property
Hal\Report\Html\Reporter::$files - [x] Access to an undefined property
Hal\Report\Html\Reporter::$project - [x] Access to an undefined property
Hal\Report\Html\Reporter::$packages - [x] Access to an undefined property
Hal\Report\Html\Reporter::$history - [x] Access to an undefined property
Hal\Violation\Class_\Blob::$metric - [x] Access to an undefined property
Hal\Violation\Class_\ProbablyBugged::$metric - [x] Access to an undefined property
Hal\Violation\Class_\TooDependent::$metric - [x] Access to an undefined property
Hal\Violation\Class_\TooLong::$metric - [x] Return type mixed of method
Hal\Component\Ast\Php5NodeTraverser::traverseArray()is not covariant with return type array of methodPhpParser\NodeTraverser::traverseArray()
Level-1 violations
- [x] Constructor of class
Hal\Component\Ast\Php7NodeTraverserhas an unused parameter$cloneNodes - [x] Variable
$commentWeightmight not be defined inHal/Metric/Class_/Component/MaintainabilityIndexVisitor.php - [x] Constructor of class
Hal\Metric\System\Packages\Composer\Composerhas an unused parameter$files - [x] Variable
$nodemight not be defined inHal/Component/Tree/Operator/CycleDetector.php
Additional changes
- [x] Replace
ActualNodeTraverserclass_aliaswithNodeTraverserFactory. This is necessary in order to makephpstanrunning without configuration. - [x] Fix progress bar doesn't show up in non-windows OS.
- [x] Add PHPStan
Notes:
- ~~Unfortunately,
Php5NodeTraversershould be excluded because of violation above.~~. Fixed with temporary solution. See https://github.com/phpstan/phpstan/issues/3557. - ~~I don't how to fix this line.~~ Fixed. https://github.com/phpmetrics/PhpMetrics/blob/62a177cdbb2319907a3f6bf8a53f899d9f76b1c9/src/Hal/Component/Tree/Operator/CycleDetector.php#L45
- Install PHPStan using
phiveto avoid dependencies conflict.
Attachment: phpstan-L0.txt phpstan-L1.txt phpstan-L2.txt
You can review this PR.
Hi @pattisahusiwa !
Thanks for the PR ! And sorry for delay :disappointed:
Can you rebase please ?
Closing this PR as current 3.x-dev branch is fixing PHPStan & Psalm issues at max levels.