Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
2 / 2 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| Metrics | |
100.00% |
2 / 2 |
|
100.00% |
2 / 2 |
3 | |
100.00% |
1 / 1 |
| __construct | n/a |
0 / 0 |
n/a |
0 / 0 |
1 | |||||
| abcScore | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| CRAP | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Jingga |
| 4 | * |
| 5 | * PHP Version 8.1 |
| 6 | * |
| 7 | * @package phpOMS\Business\Programming |
| 8 | * @copyright Dennis Eichhorn |
| 9 | * @license OMS License 2.0 |
| 10 | * @version 1.0.0 |
| 11 | * @link https://jingga.app |
| 12 | */ |
| 13 | declare(strict_types=1); |
| 14 | |
| 15 | namespace phpOMS\Business\Programming; |
| 16 | |
| 17 | /** |
| 18 | * Programming metrics |
| 19 | * |
| 20 | * This class provides basic programming metric calculations. |
| 21 | * |
| 22 | * @package phpOMS\Business\Programming |
| 23 | * @license OMS License 2.0 |
| 24 | * @link https://jingga.app |
| 25 | * @since 1.0.0 |
| 26 | */ |
| 27 | final class Metrics |
| 28 | { |
| 29 | /** |
| 30 | * Constructor |
| 31 | * |
| 32 | * @since 1.0.0 |
| 33 | * @codeCoverageIgnore |
| 34 | */ |
| 35 | private function __construct() |
| 36 | { |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Calculate ABC metric score |
| 41 | * |
| 42 | * @latex r = \sqrt{a^{2} + b^{2} + c^{2}} |
| 43 | * |
| 44 | * @param int $a Assignments |
| 45 | * @param int $b Branches |
| 46 | * @param int $c Conditionals |
| 47 | * |
| 48 | * @return int ABC metric score |
| 49 | * |
| 50 | * @since 1.0.0 |
| 51 | */ |
| 52 | public static function abcScore(int $a, int $b, int $c) : int |
| 53 | { |
| 54 | return (int) \sqrt($a * $a + $b * $b + $c * $c); |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Calculate the C.R.A.P score |
| 59 | * |
| 60 | * @latex r = com^{2} \times (1 - cov)^{3} + com |
| 61 | * |
| 62 | * @param int $complexity Complexity |
| 63 | * @param float $coverage Coverage |
| 64 | * |
| 65 | * @return int CRAP score |
| 66 | * |
| 67 | * @since 1.0.0 |
| 68 | * |
| 69 | * @SuppressWarnings(PHPMD.CamelCaseMethodName) |
| 70 | */ |
| 71 | public static function CRAP(int $complexity, float $coverage) : int |
| 72 | { |
| 73 | return (int) ($complexity ** 2 * (1 - $coverage) ** 3 + $complexity); |
| 74 | } |
| 75 | } |