Completed
Pull Request — master (#504)
by
unknown
30s
created
src/Hal/Metric/Class_/Complexity/CyclomaticComplexityVisitor.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
             // `case ...:` from a `switch`. Ignore `default:`.
97 97
             'Stmt_Case' => static fn (Stmt\Case_ $node): int => (null !== $node->cond) ? 1 : 0,
98 98
             // `... => ...` from a `match`. Ignore `default =>`.
99
-            'MatchArm' => static fn (Node\MatchArm $node): int => count((array)$node->conds)
99
+            'MatchArm' => static fn (Node\MatchArm $node) : int => count((array) $node->conds)
100 100
         ];
101 101
     }
102 102
 
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
         // Apply the CCN of the method for each method found in the class.
133 133
         /** @var array<FunctionMetric> $classMethods */
134 134
         $classMethods = $class->get('methods'); // $class->get('methods') is defined in ClassEnumVisitor.
135
-        array_map(static function (FunctionMetric $method) use ($allMethods): void {
135
+        array_map(static function(FunctionMetric $method) use ($allMethods): void {
136 136
             $methodName = $method->getName();
137 137
             $method->set('ccn', $allMethods[$methodName]['ccn']);
138 138
             $method->set('isAccessor', $allMethods[$methodName]['isAccessor']);
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
     private function discoverMethods(array $stmts): array
180 180
     {
181 181
         $methodsNames = array_map(static fn (Stmt\ClassMethod $stmt): string => $stmt->name->toString(), $stmts);
182
-        $methodsData = array_map(function (Stmt\ClassMethod $stmt): array {
182
+        $methodsData = array_map(function(Stmt\ClassMethod $stmt): array {
183 183
             $isAccessor = in_array($this->roleOfMethodDetector->detects($stmt), ['getter', 'setter'], true);
184 184
             return [
185 185
                 // Each method by default is CCN 1 even if it's empty. Ignoring accessors and give them the default CCN.
Please login to merge, or discard this patch.
src/Hal/Metric/Class_/Structural/SystemComplexityVisitor.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -69,11 +69,11 @@
 block discarded – undo
69 69
         $this->structuralComplexityByMethod = [];
70 70
         $this->localComplexityByMethod = [];
71 71
 
72
-        array_map(function (Stmt\ClassMethod $stmt): void {
72
+        array_map(function(Stmt\ClassMethod $stmt): void {
73 73
             $io = count($stmt->getParams());
74 74
             $fanOut = 0;
75 75
 
76
-            $getBasicCardAndAgrestiMetrics = static function (Node $node) use (&$io, &$fanOut): void {
76
+            $getBasicCardAndAgrestiMetrics = static function(Node $node) use (&$io, &$fanOut): void {
77 77
                 switch (true) {
78 78
                     case $node instanceof Stmt\Return_:
79 79
                         $io += (null !== $node->expr);
Please login to merge, or discard this patch.
src/Hal/Metric/Class_/Structural/LcomVisitor.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
         $class = $this->metrics->get(MetricNameGenerator::getClassName($node));
96 96
 
97 97
         // We don't want to increase the LCOM for getters and setters.
98
-        $methods = array_filter($node->getMethods(), function (Stmt\ClassMethod $stmt): bool {
98
+        $methods = array_filter($node->getMethods(), function(Stmt\ClassMethod $stmt): bool {
99 99
             return !in_array($this->roleOfMethodDetector->detects($stmt), ['getter', 'setter'], true);
100 100
         });
101 101
         array_map($this->buildGraph(...), $methods);
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
      */
119 119
     private function buildGraph(Stmt\ClassMethod $stmt): void
120 120
     {
121
-        $from = $this->graph->gather($stmt->name . '()');
121
+        $from = $this->graph->gather($stmt->name.'()');
122 122
         $this->nodeIterator->iterateOver($stmt, $this->getVisitorCallback($from));
123 123
     }
124 124
 
@@ -130,14 +130,14 @@  discard block
 block discarded – undo
130 130
      */
131 131
     private function getVisitorCallback(TreeNode $from): Closure
132 132
     {
133
-        return function (Node $node) use ($from): void {
133
+        return function(Node $node) use ($from): void {
134 134
             $relations = [
135 135
                 ...$this->getPromotedConstructorsTreeNodes($node),
136 136
                 ...$this->getPropertyFetchTreeNodes($node),
137 137
                 ...$this->getMethodCallTreeNodes($node),
138 138
             ];
139 139
 
140
-            array_map(function (TreeNode $treeNode) use ($from): void {
140
+            array_map(function(TreeNode $treeNode) use ($from): void {
141 141
                 $this->graph->addEdge($from, $treeNode);
142 142
             }, $relations);
143 143
         };
@@ -168,17 +168,17 @@  discard block
 block discarded – undo
168 168
      */
169 169
     private function getPromotedConstructorsTreeNodes(Node $node): array
170 170
     {
171
-        if (!$node instanceof Stmt\ClassMethod || '__construct' !== (string)$node->name) {
171
+        if (!$node instanceof Stmt\ClassMethod || '__construct' !== (string) $node->name) {
172 172
             return [];
173 173
         }
174 174
 
175 175
         // Promoted properties in constructors are defined by the presence of "public", "protected" or "private" flag.
176 176
         // Since PHP 8.1, the presence of "readonly" flag also promotes a property, with a "public" default visibility.
177
-        $promotions = array_filter($node->getParams(), static function (Node\Param $param): bool {
178
-            $mask = (Modifiers::VISIBILITY_MASK | Modifiers::READONLY);
179
-            return (bool)($param->flags & $mask);
177
+        $promotions = array_filter($node->getParams(), static function(Node\Param $param): bool {
178
+            $mask = (Modifiers::VISIBILITY_MASK|Modifiers::READONLY);
179
+            return (bool) ($param->flags&$mask);
180 180
         });
181
-        return array_map(function (Node\Param $param): TreeNode {
181
+        return array_map(function(Node\Param $param): TreeNode {
182 182
             /** @var Node\Expr\Variable $var Can't be an error as promoted properties are correctly parsed. */
183 183
             $var = $param->var;
184 184
             /** @var string $name Is mandatory to be a string as promoted properties cannot have expression as name. */
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
             && !$node->var instanceof Node\Expr\New_ // Prevents `(new X())->methodCall()` issues.
217 217
             && null !== ($nodeName = $this->readMemberNodeClearName($node))
218 218
         ) {
219
-            return [$this->graph->gather($nodeName . '()')];
219
+            return [$this->graph->gather($nodeName.'()')];
220 220
         }
221 221
         return [];
222 222
     }
@@ -246,10 +246,10 @@  discard block
 block discarded – undo
246 246
         if (
247 247
             property_exists($node->var, 'name')
248 248
             && !($node->var->name instanceof Node\Expr\Variable)
249
-            && 'this' === (string)$node->var->name
249
+            && 'this' === (string) $node->var->name
250 250
             && ($nodeName instanceof Stringable || is_string($nodeName))
251 251
         ) {
252
-            return (string)$nodeName;
252
+            return (string) $nodeName;
253 253
         }
254 254
         return null;
255 255
     }
Please login to merge, or discard this patch.
src/Hal/Metric/Class_/ClassEnumVisitor.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -68,13 +68,13 @@
 block discarded – undo
68 68
             $class->set('final', $node instanceof Stmt\Class_ && $node->isFinal());
69 69
         }
70 70
 
71
-        $dataMethods = (object)[
71
+        $dataMethods = (object) [
72 72
             'nbPublic' => 0,
73 73
             'nbPrivate' => 0,
74 74
         ];
75
-        $functionMetrics = array_map(function (Stmt\ClassMethod $stmt) use ($dataMethods): FunctionMetric {
75
+        $functionMetrics = array_map(function(Stmt\ClassMethod $stmt) use ($dataMethods): FunctionMetric {
76 76
             /** @var FunctionMetric $function */
77
-            $function = $this->metrics->get((string)$stmt->name);
77
+            $function = $this->metrics->get((string) $stmt->name);
78 78
             $isPublic = $stmt->isPublic();
79 79
 
80 80
             $dataMethods->nbPublic += $isPublic;
Please login to merge, or discard this patch.
src/Hal/Metric/Class_/Text/HalsteadVisitor.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
      */
88 88
     private static function getUniqueOperatorsAndOperands(): array
89 89
     {
90
-        $uniq = static function (array $elementsToDedupe): array {
90
+        $uniq = static function(array $elementsToDedupe): array {
91 91
             return array_map(unserialize(...), array_unique(array_map(serialize(...), $elementsToDedupe)));
92 92
         };
93 93
 
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
      */
185 185
     private function getVisitorCallback(): Closure
186 186
     {
187
-        return static function (Node $node): void {
187
+        return static function(Node $node): void {
188 188
             if ($node instanceof Node\Param && $node->var instanceof Node\Expr\Variable) {
189 189
                 return;
190 190
             }
Please login to merge, or discard this patch.
src/Hal/Metric/Class_/Text/LengthVisitor.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
         // Count and remove multi lines comments.
75 75
         $cloc = 0;
76 76
         preg_match_all('!/\*.*?\*/!s', $code, $matches);
77
-        array_map(function (string $commentedCode) use (&$cloc): void {
77
+        array_map(function(string $commentedCode) use (&$cloc): void {
78 78
             $cloc += max(1, $this->countSplitLines($commentedCode));
79 79
         }, $matches[0]);
80 80
         /** @var string $code subject and replacement are string, so the return remains a string. */
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
         /** @var string $code subject and replacement are string, so the return remains a string. */
85 85
         $code = preg_replace_callback(
86 86
             '!(\'[^\']*\'|"[^"]*")|((?:#[^\[]|//).*$)!m',
87
-            static function (array $matches) use (&$cloc): string {
87
+            static function(array $matches) use (&$cloc): string {
88 88
                 [, $logicalCode, $commentedCode] = array_pad($matches, 3, null);
89 89
                 $cloc += (null !== $commentedCode);
90 90
                 /** @var string */
Please login to merge, or discard this patch.
src/Hal/Metric/Class_/Coupling/ExternalsVisitor.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
      */
115 115
     private function addDependency(string|Stringable $dependency): void
116 116
     {
117
-        $dependency = (string)$dependency;
117
+        $dependency = (string) $dependency;
118 118
         if (in_array(strtolower($dependency), ['self', 'parent'], true)) {
119 119
             return;
120 120
         }
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
      */
130 130
     private function addParent(string|Stringable $parent): void
131 131
     {
132
-        $parent = (string)$parent;
132
+        $parent = (string) $parent;
133 133
         $this->parents[] = ltrim($parent, '\\');
134 134
         // Parenting is a dependency.
135 135
         $this->addDependency($parent);
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
      */
142 142
     private function addImplementation(string|Stringable $implements): void
143 143
     {
144
-        $implements = (string)$implements;
144
+        $implements = (string) $implements;
145 145
         $this->interfaces[] = ltrim($implements, '\\');
146 146
         // Implementation is a dependency.
147 147
         $this->addDependency($implements);
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
         $this->addDependenciesFromTypeHint($stmt->returnType);
159 159
 
160 160
         // Type hint of method's arguments
161
-        array_map(function (Node\Param $param): void {
161
+        array_map(function(Node\Param $param): void {
162 162
             $this->addDependenciesFromTypeHint($param->type);
163 163
         }, $stmt->params);
164 164
 
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
         // - MyClass::$staticProperty;
169 169
         // - MyClass::class;
170 170
         // - instanceof MyClass;
171
-        $this->nodeIterator->iterateOver($stmt, function (Node $node): void {
171
+        $this->nodeIterator->iterateOver($stmt, function(Node $node): void {
172 172
             if ($node instanceof Node\Expr && property_exists($node, 'class') && $node->class instanceof Node\Name) {
173 173
                 $this->addDependency($node->class);
174 174
             }
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
         $comments = $node->getDocComment();
212 212
         /** @var scalar $reformattedTest */
213 213
         $reformattedTest = $comments?->getReformattedText();
214
-        preg_match_all('!\s+\*\s+@([\w\\\\]+)!', (string)$reformattedTest, $matches);
214
+        preg_match_all('!\s+\*\s+@([\w\\\\]+)!', (string) $reformattedTest, $matches);
215 215
         $annotations = $matches[1] ?? [];
216 216
         array_map($this->addDependency(...), $annotations);
217 217
     }
@@ -232,12 +232,12 @@  discard block
 block discarded – undo
232 232
 
233 233
         // Otherwise, check with the defined `use` statements.
234 234
         foreach ($this->uses as $use) {
235
-            $useAlias = (string)$use->getAlias();
235
+            $useAlias = (string) $use->getAlias();
236 236
             if ($useAlias === $classNameToResolve && !str_contains($classNameToResolve, '\\')) {
237
-                return (string)$use->name;
237
+                return (string) $use->name;
238 238
             }
239 239
             if ($useAlias === strstr($classNameToResolve, '\\', true)) {
240
-                return $use->name . strstr($classNameToResolve, '\\');
240
+                return $use->name.strstr($classNameToResolve, '\\');
241 241
             }
242 242
         }
243 243
 
Please login to merge, or discard this patch.
src/Hal/Metric/Class_/Component/MaintainabilityIndexVisitor.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -77,13 +77,13 @@
 block discarded – undo
77 77
         $volume = $class->get('volume');
78 78
 
79 79
         if (null === $lloc || null === $cloc || null === $loc) {
80
-            throw new LogicException('Please enable ' . LengthVisitor::class . ' visitor first');
80
+            throw new LogicException('Please enable '.LengthVisitor::class.' visitor first');
81 81
         }
82 82
         if (null === $ccn) {
83
-            throw new LogicException('Please enable ' . CyclomaticComplexityVisitor::class . ' visitor first');
83
+            throw new LogicException('Please enable '.CyclomaticComplexityVisitor::class.' visitor first');
84 84
         }
85 85
         if (null === $volume) {
86
-            throw new LogicException('Please enable ' . HalsteadVisitor::class . ' visitor first');
86
+            throw new LogicException('Please enable '.HalsteadVisitor::class.' visitor first');
87 87
         }
88 88
 
89 89
         // Maintainability index without comment.
Please login to merge, or discard this patch.
src/Hal/Metric/Group/Group.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -40,7 +40,7 @@
 block discarded – undo
40 40
     public function reduceMetrics(Metrics $metrics): Metrics
41 41
     {
42 42
         $matched = new Metrics();
43
-        array_map(function (Metric $metric) use ($matched): void {
43
+        array_map(function(Metric $metric) use ($matched): void {
44 44
             if (1 !== preg_match($this->getRegex(), $metric->getName())) {
45 45
                 return;
46 46
             }
Please login to merge, or discard this patch.