PhpMetrics icon indicating copy to clipboard operation
PhpMetrics copied to clipboard

Fix phpstan level-0 and level-1 violations and some bugs

Open pattisahusiwa opened this issue 4 years ago • 2 comments

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\ViolationParser does 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 method PhpParser\NodeTraverser::traverseArray()

Level-1 violations

  • [x] Constructor of class Hal\Component\Ast\Php7NodeTraverser has an unused parameter $cloneNodes
  • [x] Variable $commentWeight might not be defined in Hal/Metric/Class_/Component/MaintainabilityIndexVisitor.php
  • [x] Constructor of class Hal\Metric\System\Packages\Composer\Composer has an unused parameter $files
  • [x] Variable $node might not be defined in Hal/Component/Tree/Operator/CycleDetector.php

Additional changes

  • [x] Replace ActualNodeTraverser class_alias with NodeTraverserFactory. This is necessary in order to make phpstan running without configuration.
  • [x] Fix progress bar doesn't show up in non-windows OS.
  • [x] Add PHPStan

Notes:

  1. ~~Unfortunately, Php5NodeTraverser should be excluded because of violation above.~~. Fixed with temporary solution. See https://github.com/phpstan/phpstan/issues/3557.
  2. ~~I don't how to fix this line.~~ Fixed. https://github.com/phpmetrics/PhpMetrics/blob/62a177cdbb2319907a3f6bf8a53f899d9f76b1c9/src/Hal/Component/Tree/Operator/CycleDetector.php#L45
  3. Install PHPStan using phive to avoid dependencies conflict.

Attachment: phpstan-L0.txt phpstan-L1.txt phpstan-L2.txt

pattisahusiwa avatar Jun 30 '20 10:06 pattisahusiwa

You can review this PR.

pattisahusiwa avatar Jul 02 '20 20:07 pattisahusiwa

Hi @pattisahusiwa !

Thanks for the PR ! And sorry for delay :disappointed:

Can you rebase please ?

Halleck45 avatar Mar 25 '22 10:03 Halleck45

Closing this PR as current 3.x-dev branch is fixing PHPStan & Psalm issues at max levels.

niconoe- avatar Sep 15 '23 14:09 niconoe-