| @@ 9-62 (lines=54) @@ | ||
| 6 | use Hal\Metric\Metric; |
|
| 7 | use Hal\Violation\Violation; |
|
| 8 | ||
| 9 | class ProbablyBugged implements Violation |
|
| 10 | { |
|
| 11 | ||
| 12 | /** |
|
| 13 | * @inheritdoc |
|
| 14 | */ |
|
| 15 | public function getName() |
|
| 16 | { |
|
| 17 | return 'Probably bugged'; |
|
| 18 | } |
|
| 19 | ||
| 20 | /** |
|
| 21 | * @inheritdoc |
|
| 22 | */ |
|
| 23 | public function apply(Metric $metric) |
|
| 24 | { |
|
| 25 | if (!$metric instanceof ClassMetric) { |
|
| 26 | return; |
|
| 27 | } |
|
| 28 | ||
| 29 | $this->metric = $metric; |
|
| 30 | ||
| 31 | $suspect = 0; |
|
| 32 | if ($metric->get('bugs') >= .35) { |
|
| 33 | $metric->get('violations')->add($this); |
|
| 34 | return; |
|
| 35 | } |
|
| 36 | } |
|
| 37 | ||
| 38 | /** |
|
| 39 | * @inheritdoc |
|
| 40 | */ |
|
| 41 | public function getLevel() |
|
| 42 | { |
|
| 43 | return Violation::WARNING; |
|
| 44 | } |
|
| 45 | ||
| 46 | /** |
|
| 47 | * @inheritdoc |
|
| 48 | */ |
|
| 49 | public function getDescription() |
|
| 50 | { |
|
| 51 | return <<<EOT |
|
| 52 | This component contains in theory {$this->metric->get('bugs')} bugs. |
|
| 53 | ||
| 54 | * Calculation is based on number of operators, operands, cyclomatic complexity |
|
| 55 | * See more details at https://en.wikipedia.org/wiki/Halstead_complexity_measures |
|
| 56 | * {$this->metric->get('numberOfUnitTests')} testsuites has dependency to this class. |
|
| 57 | ||
| 58 | Maybe you should check your unit tests for this class. |
|
| 59 | EOT; |
|
| 60 | ||
| 61 | } |
|
| 62 | } |
|
| 63 | ||
| @@ 9-60 (lines=52) @@ | ||
| 6 | use Hal\Metric\Metric; |
|
| 7 | use Hal\Violation\Violation; |
|
| 8 | ||
| 9 | class TooDependent implements Violation |
|
| 10 | { |
|
| 11 | ||
| 12 | /** |
|
| 13 | * @inheritdoc |
|
| 14 | */ |
|
| 15 | public function getName() |
|
| 16 | { |
|
| 17 | return 'Too dependent'; |
|
| 18 | } |
|
| 19 | ||
| 20 | /** |
|
| 21 | * @inheritdoc |
|
| 22 | */ |
|
| 23 | public function apply(Metric $metric) |
|
| 24 | { |
|
| 25 | if (!$metric instanceof ClassMetric) { |
|
| 26 | return; |
|
| 27 | } |
|
| 28 | ||
| 29 | $this->metric = $metric; |
|
| 30 | ||
| 31 | if ($metric->get('efferentCoupling') >= 20) { |
|
| 32 | $metric->get('violations')->add($this); |
|
| 33 | return; |
|
| 34 | } |
|
| 35 | ||
| 36 | } |
|
| 37 | ||
| 38 | /** |
|
| 39 | * @inheritdoc |
|
| 40 | */ |
|
| 41 | public function getLevel() |
|
| 42 | { |
|
| 43 | return Violation::INFO; |
|
| 44 | } |
|
| 45 | ||
| 46 | /** |
|
| 47 | * @inheritdoc |
|
| 48 | */ |
|
| 49 | public function getDescription() |
|
| 50 | { |
|
| 51 | return <<<EOT |
|
| 52 | This class looks use really high number of components. |
|
| 53 | ||
| 54 | * Efferent coupling is {$this->metric->get('efferentCoupling')}, so this class uses {$this->metric->get('efferentCoupling')} differents external components. |
|
| 55 | ||
| 56 | Maybe you should check why this class has lot of dependencies. |
|
| 57 | EOT; |
|
| 58 | ||
| 59 | } |
|
| 60 | } |
|
| 61 | ||
| @@ 9-59 (lines=51) @@ | ||
| 6 | use Hal\Metric\Metric; |
|
| 7 | use Hal\Violation\Violation; |
|
| 8 | ||
| 9 | class TooLong implements Violation |
|
| 10 | { |
|
| 11 | ||
| 12 | /** |
|
| 13 | * @inheritdoc |
|
| 14 | */ |
|
| 15 | public function getName() |
|
| 16 | { |
|
| 17 | return 'Too long'; |
|
| 18 | } |
|
| 19 | ||
| 20 | /** |
|
| 21 | * @inheritdoc |
|
| 22 | */ |
|
| 23 | public function apply(Metric $metric) |
|
| 24 | { |
|
| 25 | if (!$metric instanceof ClassMetric) { |
|
| 26 | return; |
|
| 27 | } |
|
| 28 | ||
| 29 | $this->metric = $metric; |
|
| 30 | ||
| 31 | if ($metric->get('lloc') >= 200) { |
|
| 32 | $metric->get('violations')->add($this); |
|
| 33 | } |
|
| 34 | } |
|
| 35 | ||
| 36 | /** |
|
| 37 | * @inheritdoc |
|
| 38 | */ |
|
| 39 | public function getLevel() |
|
| 40 | { |
|
| 41 | return Violation::INFO; |
|
| 42 | } |
|
| 43 | ||
| 44 | /** |
|
| 45 | * @inheritdoc |
|
| 46 | */ |
|
| 47 | public function getDescription() |
|
| 48 | { |
|
| 49 | return <<<EOT |
|
| 50 | This class looks really long. |
|
| 51 | ||
| 52 | * Class has {$this->metric->get('lloc')} logical lines of code |
|
| 53 | * Class has {$this->metric->get('loc')} lines of code |
|
| 54 | ||
| 55 | Maybe your class should not exceed 200 lines of logical code |
|
| 56 | EOT; |
|
| 57 | ||
| 58 | } |
|
| 59 | } |
|
| 60 | ||
| @@ 9-61 (lines=53) @@ | ||
| 6 | use Hal\Metric\Metric; |
|
| 7 | use Hal\Violation\Violation; |
|
| 8 | ||
| 9 | class TooComplexClassCode implements Violation |
|
| 10 | { |
|
| 11 | ||
| 12 | /** |
|
| 13 | * @inheritdoc |
|
| 14 | */ |
|
| 15 | public function getName() |
|
| 16 | { |
|
| 17 | return 'Too complex class code'; |
|
| 18 | } |
|
| 19 | ||
| 20 | /** |
|
| 21 | * @inheritdoc |
|
| 22 | */ |
|
| 23 | public function apply(Metric $metric) |
|
| 24 | { |
|
| 25 | if (!$metric instanceof ClassMetric) { |
|
| 26 | return; |
|
| 27 | } |
|
| 28 | ||
| 29 | $this->metric = $metric; |
|
| 30 | ||
| 31 | if ($metric->get('ccn') >= 25) { |
|
| 32 | $metric->get('violations')->add($this); |
|
| 33 | return; |
|
| 34 | } |
|
| 35 | ||
| 36 | } |
|
| 37 | ||
| 38 | /** |
|
| 39 | * @inheritdoc |
|
| 40 | */ |
|
| 41 | public function getLevel() |
|
| 42 | { |
|
| 43 | return Violation::ERROR; |
|
| 44 | } |
|
| 45 | ||
| 46 | /** |
|
| 47 | * @inheritdoc |
|
| 48 | */ |
|
| 49 | public function getDescription() |
|
| 50 | { |
|
| 51 | return <<<EOT |
|
| 52 | This class looks really complex. |
|
| 53 | ||
| 54 | * Algorithms are complex (Total cyclomatic complexity of class is {$this->metric->get('ccn')}) |
|
| 55 | * Component uses {$this->metric->get('number_operators')} operators |
|
| 56 | ||
| 57 | Maybe you should delegate some code to other objects. |
|
| 58 | EOT; |
|
| 59 | ||
| 60 | } |
|
| 61 | } |
|
| 62 | ||
| @@ 9-60 (lines=52) @@ | ||
| 6 | use Hal\Metric\Metric; |
|
| 7 | use Hal\Violation\Violation; |
|
| 8 | ||
| 9 | class TooComplexMethodCode implements Violation |
|
| 10 | { |
|
| 11 | ||
| 12 | /** |
|
| 13 | * @inheritdoc |
|
| 14 | */ |
|
| 15 | public function getName() |
|
| 16 | { |
|
| 17 | return 'Too complex method code'; |
|
| 18 | } |
|
| 19 | ||
| 20 | /** |
|
| 21 | * @inheritdoc |
|
| 22 | */ |
|
| 23 | public function apply(Metric $metric) |
|
| 24 | { |
|
| 25 | if (!$metric instanceof ClassMetric) { |
|
| 26 | return; |
|
| 27 | } |
|
| 28 | ||
| 29 | $this->metric = $metric; |
|
| 30 | ||
| 31 | if ($metric->get('ccnMethodMax') >= 8) { |
|
| 32 | $metric->get('violations')->add($this); |
|
| 33 | return; |
|
| 34 | } |
|
| 35 | ||
| 36 | } |
|
| 37 | ||
| 38 | /** |
|
| 39 | * @inheritdoc |
|
| 40 | */ |
|
| 41 | public function getLevel() |
|
| 42 | { |
|
| 43 | return Violation::ERROR; |
|
| 44 | } |
|
| 45 | ||
| 46 | /** |
|
| 47 | * @inheritdoc |
|
| 48 | */ |
|
| 49 | public function getDescription() |
|
| 50 | { |
|
| 51 | return <<<EOT |
|
| 52 | This class looks really complex. |
|
| 53 | ||
| 54 | * Algorithms are complex (Max cyclomatic complexity of class methods is {$this->metric->get('ccnMethodMax')}) |
|
| 55 | ||
| 56 | Maybe you should delegate some code to other objects or split complex method. |
|
| 57 | EOT; |
|
| 58 | ||
| 59 | } |
|
| 60 | } |
|
| 61 | ||