|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Phauthentic\CognitiveCodeAnalysis\Business\Cyclomatic; |
| 6 | + |
| 7 | +/** |
| 8 | + * @SuppressWarnings(TooManyFields) |
| 9 | + */ |
| 10 | +class CyclomaticMetrics |
| 11 | +{ |
| 12 | + /** |
| 13 | + * The cyclomatic complexity value. |
| 14 | + * @var int |
| 15 | + */ |
| 16 | + public int $complexity; |
| 17 | + |
| 18 | + /** |
| 19 | + * The risk level associated with the complexity. |
| 20 | + * @var string |
| 21 | + */ |
| 22 | + public string $riskLevel; |
| 23 | + |
| 24 | + /** |
| 25 | + * The total number of decision points. |
| 26 | + * @var int |
| 27 | + */ |
| 28 | + public int $totalCount; |
| 29 | + |
| 30 | + /** |
| 31 | + * The base complexity (usually 1). |
| 32 | + * @var int |
| 33 | + */ |
| 34 | + public int $baseCount; |
| 35 | + |
| 36 | + /** |
| 37 | + * Number of if statements. |
| 38 | + * @var int |
| 39 | + */ |
| 40 | + public int $ifCount; |
| 41 | + |
| 42 | + /** |
| 43 | + * Number of elseif statements. |
| 44 | + * @var int |
| 45 | + */ |
| 46 | + public int $elseifCount; |
| 47 | + |
| 48 | + /** |
| 49 | + * Number of else statements. |
| 50 | + * @var int |
| 51 | + */ |
| 52 | + public int $elseCount; |
| 53 | + |
| 54 | + /** |
| 55 | + * Number of switch statements. |
| 56 | + * @var int |
| 57 | + */ |
| 58 | + public int $switchCount; |
| 59 | + |
| 60 | + /** |
| 61 | + * Number of case statements. |
| 62 | + * @var int |
| 63 | + */ |
| 64 | + public int $caseCount; |
| 65 | + |
| 66 | + /** |
| 67 | + * Number of default statements. |
| 68 | + * @var int |
| 69 | + */ |
| 70 | + public int $defaultCount; |
| 71 | + |
| 72 | + /** |
| 73 | + * Number of while loops. |
| 74 | + * @var int |
| 75 | + */ |
| 76 | + public int $whileCount; |
| 77 | + |
| 78 | + /** |
| 79 | + * Number of do-while loops. |
| 80 | + * @var int |
| 81 | + */ |
| 82 | + public int $doWhileCount; |
| 83 | + |
| 84 | + /** |
| 85 | + * Number of for loops. |
| 86 | + * @var int |
| 87 | + */ |
| 88 | + public int $forCount; |
| 89 | + |
| 90 | + /** |
| 91 | + * Number of foreach loops. |
| 92 | + * @var int |
| 93 | + */ |
| 94 | + public int $foreachCount; |
| 95 | + |
| 96 | + /** |
| 97 | + * Number of catch blocks. |
| 98 | + * @var int |
| 99 | + */ |
| 100 | + public int $catchCount; |
| 101 | + |
| 102 | + /** |
| 103 | + * Number of logical AND (&&) operations. |
| 104 | + * @var int |
| 105 | + */ |
| 106 | + public int $logicalAndCount; |
| 107 | + |
| 108 | + /** |
| 109 | + * Number of logical OR (||) operations. |
| 110 | + * @var int |
| 111 | + */ |
| 112 | + public int $logicalOrCount; |
| 113 | + |
| 114 | + /** |
| 115 | + * Number of logical XOR operations. |
| 116 | + * @var int |
| 117 | + */ |
| 118 | + public int $logicalXorCount; |
| 119 | + |
| 120 | + /** |
| 121 | + * Number of ternary operations. |
| 122 | + * @var int |
| 123 | + */ |
| 124 | + public int $ternaryCount; |
| 125 | + |
| 126 | + /** |
| 127 | + * @param array<string, mixed> $data |
| 128 | + */ |
| 129 | + public function __construct(array $data) |
| 130 | + { |
| 131 | + |
| 132 | + $this->complexity = $data['complexity'] ?? 1; |
| 133 | + $this->riskLevel = (string)($data['risk_level'] ?? $data['riskLevel'] ?? 'unknown'); |
| 134 | + $this->totalCount = $data['totalCount'] ?? $data['breakdown']['total'] ?? 0; |
| 135 | + $this->baseCount = $data['baseCount'] ?? $data['breakdown']['base'] ?? 1; |
| 136 | + $this->ifCount = $data['ifCount'] ?? $data['breakdown']['if'] ?? 0; |
| 137 | + $this->elseifCount = $data['elseifCount'] ?? $data['breakdown']['elseif'] ?? 0; |
| 138 | + $this->elseCount = $data['elseCount'] ?? $data['breakdown']['else'] ?? 0; |
| 139 | + $this->switchCount = $data['switchCount'] ?? $data['breakdown']['switch'] ?? 0; |
| 140 | + $this->caseCount = $data['caseCount'] ?? $data['breakdown']['case'] ?? 0; |
| 141 | + $this->defaultCount = $data['defaultCount'] ?? $data['breakdown']['default'] ?? 0; |
| 142 | + $this->whileCount = $data['whileCount'] ?? $data['breakdown']['while'] ?? 0; |
| 143 | + $this->doWhileCount = $data['doWhileCount'] ?? $data['breakdown']['do_while'] ?? 0; |
| 144 | + $this->forCount = $data['forCount'] ?? $data['breakdown']['for'] ?? 0; |
| 145 | + $this->foreachCount = $data['foreachCount'] ?? $data['breakdown']['foreach'] ?? 0; |
| 146 | + $this->catchCount = $data['catchCount'] ?? $data['breakdown']['catch'] ?? 0; |
| 147 | + $this->logicalAndCount = $data['logicalAndCount'] ?? $data['breakdown']['logical_and'] ?? 0; |
| 148 | + $this->logicalOrCount = $data['logicalOrCount'] ?? $data['breakdown']['logical_or'] ?? 0; |
| 149 | + $this->logicalXorCount = $data['logicalXorCount'] ?? $data['breakdown']['logical_xor'] ?? 0; |
| 150 | + $this->ternaryCount = $data['ternaryCount'] ?? $data['breakdown']['ternary'] ?? 0; |
| 151 | + } |
| 152 | +} |
0 commit comments