@@ -11,7 +11,6 @@ |
||
11 | 11 | use Hal\Component\OOP\Reflected\MethodUsage; |
12 | 12 | use Hal\Component\OOP\Reflected\ReflectedArgument; |
13 | 13 | use Hal\Component\OOP\Reflected\ReflectedClass; |
14 | -use Hal\Component\OOP\Reflected\ReflectedClass\ReflectedAnonymousClass; |
|
15 | 14 | use Hal\Component\OOP\Reflected\ReflectedMethod; |
16 | 15 | use Hal\Component\OOP\Reflected\ReflectedReturn; |
17 | 16 | use Hal\Component\OOP\Resolver\TypeResolver; |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | $start = $n; |
56 | 56 | |
57 | 57 | $declaration = $this->searcher->getUnder(array(')'), $n, $tokens); |
58 | - if(!preg_match('!function\s+(.*)\(\s*(.*)!is', $declaration, $matches)) { |
|
58 | + if (!preg_match('!function\s+(.*)\(\s*(.*)!is', $declaration, $matches)) { |
|
59 | 59 | throw new \Exception(sprintf("Closure detected instead of method\nDetails:\n%s", $declaration)); |
60 | 60 | } |
61 | 61 | list(, $name, $args) = $matches; |
@@ -68,21 +68,21 @@ discard block |
||
68 | 68 | $this->extractState($method, $p = $start, $tokens); // please keep "p = start" |
69 | 69 | |
70 | 70 | $arguments = preg_split('!\s*,\s*!m', $args); |
71 | - foreach($arguments as $argDecl) { |
|
71 | + foreach ($arguments as $argDecl) { |
|
72 | 72 | |
73 | - if(0 == strlen($argDecl)) { |
|
73 | + if (0 == strlen($argDecl)) { |
|
74 | 74 | continue; |
75 | 75 | } |
76 | 76 | |
77 | 77 | $elems = preg_split('!([\s=]+)!', $argDecl); |
78 | 78 | $isRequired = 2 == sizeof($elems, COUNT_NORMAL); |
79 | 79 | |
80 | - if(sizeof($elems, COUNT_NORMAL) == 1) { |
|
80 | + if (sizeof($elems, COUNT_NORMAL) == 1) { |
|
81 | 81 | list($name, $type) = array_pad($elems, 2, null); |
82 | 82 | } else { |
83 | - if('$' == $elems[0][0]) { |
|
83 | + if ('$' == $elems[0][0]) { |
|
84 | 84 | $name = $elems[0]; |
85 | - $type = null; |
|
85 | + $type = null; |
|
86 | 86 | $isRequired = false; |
87 | 87 | } else { |
88 | 88 | list($type, $name) = array_pad($elems, 2, null); |
@@ -96,9 +96,9 @@ discard block |
||
96 | 96 | |
97 | 97 | |
98 | 98 | // does method has body ? (example: interface ; abstract classes) |
99 | - $p = $n + 1; |
|
99 | + $p = $n + 1; |
|
100 | 100 | $underComma = trim($this->searcher->getUnder(array(';'), $p, $tokens)); |
101 | - if(strlen($underComma) > 0) { |
|
101 | + if (strlen($underComma) > 0) { |
|
102 | 102 | // |
103 | 103 | // Body |
104 | 104 | $this->extractContent($method, $n, $tokens); |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | |
109 | 109 | // Tokens |
110 | 110 | $end = $this->searcher->getPositionOfClosingBrace($n, $tokens); |
111 | - if($end > 0) { |
|
111 | + if ($end > 0) { |
|
112 | 112 | $method->setTokens($tokens->extract($n, $end)); |
113 | 113 | } |
114 | 114 | } else { |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | * @return $this |
139 | 139 | */ |
140 | 140 | public function extractVisibility(ReflectedMethod $method, $n, TokenCollection $tokens) { |
141 | - switch(true) { |
|
141 | + switch (true) { |
|
142 | 142 | case $this->searcher->isPrecededBy(T_PRIVATE, $n, $tokens, 4): |
143 | 143 | $visibility = ReflectedMethod::VISIBILITY_PRIVATE; |
144 | 144 | break; |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | * @return $this |
164 | 164 | */ |
165 | 165 | public function extractState(ReflectedMethod $method, $n, TokenCollection $tokens) { |
166 | - if($this->searcher->isPrecededBy(T_STATIC, $n, $tokens, 4)) { |
|
166 | + if ($this->searcher->isPrecededBy(T_STATIC, $n, $tokens, 4)) { |
|
167 | 167 | $method->setState(ReflectedMethod::STATE_STATIC); |
168 | 168 | } |
169 | 169 | return $this; |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | */ |
180 | 180 | private function extractContent(ReflectedMethod $method, $n, TokenCollection $tokens) { |
181 | 181 | $end = $this->searcher->getPositionOfClosingBrace($n, $tokens); |
182 | - if($end > 0) { |
|
182 | + if ($end > 0) { |
|
183 | 183 | $collection = $tokens->extract($n, $end); |
184 | 184 | $method->setContent($collection->asString()); |
185 | 185 | } |
@@ -202,13 +202,13 @@ discard block |
||
202 | 202 | $extractor = new CallExtractor($this->searcher, $currentClass); |
203 | 203 | $start = $n; |
204 | 204 | $len = sizeof($tokens, COUNT_NORMAL); |
205 | - for($i = $start; $i < $len; $i++) { |
|
205 | + for ($i = $start; $i < $len; $i++) { |
|
206 | 206 | $token = $tokens[$i]; |
207 | - switch($token->getType()) { |
|
207 | + switch ($token->getType()) { |
|
208 | 208 | case T_PAAMAYIM_NEKUDOTAYIM: |
209 | 209 | case T_NEW: |
210 | 210 | $call = $extractor->extract($i, $tokens, $currentClass); |
211 | - if($call !== 'class') { // anonymous class |
|
211 | + if ($call !== 'class') { // anonymous class |
|
212 | 212 | $method->pushDependency($call); |
213 | 213 | $method->pushInstanciedClass($call); |
214 | 214 | } |
@@ -219,9 +219,9 @@ discard block |
||
219 | 219 | // |
220 | 220 | // Parameters in Method API |
221 | 221 | $resolver = new TypeResolver(); |
222 | - foreach($method->getArguments() as $argument) { |
|
222 | + foreach ($method->getArguments() as $argument) { |
|
223 | 223 | $name = $argument->getType(); |
224 | - if(strlen($name) > 0 && !$resolver->isNative($name)) { |
|
224 | + if (strlen($name) > 0 && !$resolver->isNative($name)) { |
|
225 | 225 | $method->pushDependency($name); |
226 | 226 | } |
227 | 227 | } |
@@ -240,10 +240,10 @@ discard block |
||
240 | 240 | private function extractCalls(ReflectedMethod $method, $n, TokenCollection $tokens) { |
241 | 241 | |
242 | 242 | // $this->foo(), $c->foo() |
243 | - if(preg_match_all('!(\$[\w]*)\-\>(\w*?)\(!', $method->getContent(), $matches, PREG_SET_ORDER)) { |
|
244 | - foreach($matches as $m) { |
|
243 | + if (preg_match_all('!(\$[\w]*)\-\>(\w*?)\(!', $method->getContent(), $matches, PREG_SET_ORDER)) { |
|
244 | + foreach ($matches as $m) { |
|
245 | 245 | $function = $m[2]; |
246 | - if('$this' == $m[1]) { |
|
246 | + if ('$this' == $m[1]) { |
|
247 | 247 | $method->pushInternalCall($function); |
248 | 248 | } else { |
249 | 249 | $method->pushExternalCall($m[1], $function); |
@@ -251,8 +251,8 @@ discard block |
||
251 | 251 | } |
252 | 252 | } |
253 | 253 | // (new X)->foo() |
254 | - if(preg_match_all('!\(new (\w+?).*?\)\->(\w+)\(!', $method->getContent(), $matches, PREG_SET_ORDER)) { |
|
255 | - foreach($matches as $m) { |
|
254 | + if (preg_match_all('!\(new (\w+?).*?\)\->(\w+)\(!', $method->getContent(), $matches, PREG_SET_ORDER)) { |
|
255 | + foreach ($matches as $m) { |
|
256 | 256 | $method->pushExternalCall($m[1], $m[2]); |
257 | 257 | } |
258 | 258 | } |
@@ -272,9 +272,9 @@ discard block |
||
272 | 272 | // we cannot use specific token. The ":" delimiter is a T_STRING token |
273 | 273 | // in regex we match ":" followed by any character except another ":" |
274 | 274 | $following = $this->searcher->getUnder(array('{', ';'), $n, $tokens); |
275 | - if(preg_match('@(?<!:):\s*(\w+)@', $following, $matches)) { |
|
275 | + if (preg_match('@(?<!:):\s*(\w+)@', $following, $matches)) { |
|
276 | 276 | $type = trim($matches[1]); |
277 | - if(empty($type)) { |
|
277 | + if (empty($type)) { |
|
278 | 278 | return $this; |
279 | 279 | } |
280 | 280 | $return = new ReflectedReturn($type, ReflectedReturn::VALUE_UNKNOW, ReflectedReturn::STRICT_TYPE_HINT); |
@@ -283,8 +283,8 @@ discard block |
||
283 | 283 | } |
284 | 284 | |
285 | 285 | // array of available values based on code |
286 | - if(preg_match_all('!([\s;]return\s|^return\s+)(.*?);!', $method->getContent(), $matches)) { |
|
287 | - foreach($matches[2] as $m) { |
|
286 | + if (preg_match_all('!([\s;]return\s|^return\s+)(.*?);!', $method->getContent(), $matches)) { |
|
287 | + foreach ($matches[2] as $m) { |
|
288 | 288 | $value = trim($m, ";\t\n\r\0\x0B"); |
289 | 289 | $return = new ReflectedReturn($resolver->resolve($m), $value, ReflectedReturn::ESTIMATED_TYPE_HINT); |
290 | 290 | $method->pushReturn($return); |
@@ -302,21 +302,21 @@ discard block |
||
302 | 302 | private function extractUsage(ReflectedMethod $method) { |
303 | 303 | $tokens = $method->getTokens(); |
304 | 304 | $codes = $values = array(); |
305 | - foreach($tokens as $token) { |
|
306 | - if(in_array($token->getType(), array(T_WHITESPACE, T_BOOL_CAST, T_INT_CAST, T_STRING_CAST, T_DOUBLE_CAST, T_OBJECT_CAST))) { |
|
305 | + foreach ($tokens as $token) { |
|
306 | + if (in_array($token->getType(), array(T_WHITESPACE, T_BOOL_CAST, T_INT_CAST, T_STRING_CAST, T_DOUBLE_CAST, T_OBJECT_CAST))) { |
|
307 | 307 | continue; |
308 | 308 | } |
309 | 309 | array_push($codes, $token->getType()); |
310 | 310 | array_push($values, $token->getValue()); |
311 | 311 | } |
312 | - switch(true) { |
|
313 | - case preg_match('!^(get)|(is)|(has).*!',$method->getName()) && $codes == array(T_RETURN, T_VARIABLE, T_OBJECT_OPERATOR, T_STRING, T_STRING): |
|
312 | + switch (true) { |
|
313 | + case preg_match('!^(get)|(is)|(has).*!', $method->getName()) && $codes == array(T_RETURN, T_VARIABLE, T_OBJECT_OPERATOR, T_STRING, T_STRING): |
|
314 | 314 | $method->setUsage(MethodUsage::USAGE_GETTER); |
315 | 315 | break; |
316 | 316 | // basic setter |
317 | - case preg_match('!^set.*!',$method->getName()) && $codes == array(T_VARIABLE, T_OBJECT_OPERATOR,T_STRING,T_STRING, T_VARIABLE, T_STRING) && $values[3] == '=': |
|
317 | + case preg_match('!^set.*!', $method->getName()) && $codes == array(T_VARIABLE, T_OBJECT_OPERATOR, T_STRING, T_STRING, T_VARIABLE, T_STRING) && $values[3] == '=': |
|
318 | 318 | // fluent setter |
319 | - case preg_match('!^set.*!',$method->getName()) && $codes == array(T_VARIABLE, T_OBJECT_OPERATOR,T_STRING,T_STRING, T_VARIABLE, T_STRING, T_RETURN, T_VARIABLE, T_STRING) |
|
319 | + case preg_match('!^set.*!', $method->getName()) && $codes == array(T_VARIABLE, T_OBJECT_OPERATOR, T_STRING, T_STRING, T_VARIABLE, T_STRING, T_RETURN, T_VARIABLE, T_STRING) |
|
320 | 320 | && $values[3] == '=' && $values[7] == '$this': |
321 | 321 | $method->setUsage(MethodUsage::USAGE_SETTER); |
322 | 322 | break; |
@@ -1,4 +1,4 @@ |
||
1 | 1 | <?php |
2 | 2 | // PHP 7 |
3 | -defined('T_SPACESHIP') ||define('T_SPACESHIP', '<=>'); // 289 |
|
4 | -defined('T_COALESCE') ||define('T_COALESCE', '??'); // 282 |
|
5 | 3 | \ No newline at end of file |
4 | +defined('T_SPACESHIP') || define('T_SPACESHIP', '<=>'); // 289 |
|
5 | +defined('T_COALESCE') || define('T_COALESCE', '??'); // 282 |
|
6 | 6 | \ No newline at end of file |
@@ -134,7 +134,7 @@ |
||
134 | 134 | ->setHalstead($rHalstead) |
135 | 135 | ->setMaintainabilityIndex($rMaintainability); |
136 | 136 | |
137 | - if($this->withOOP) { |
|
137 | + if ($this->withOOP) { |
|
138 | 138 | $rOOP = $this->extractor->extract($filename); |
139 | 139 | $this->classMap->push($filename, $rOOP); |
140 | 140 | $resultSet->setOOP($rOOP); |
@@ -47,7 +47,7 @@ |
||
47 | 47 | |
48 | 48 | public function execute(array $files) { |
49 | 49 | $fileCoupling = new FileLackOfCohesionOfMethods($this->classMap); |
50 | - foreach($files as $filename) { |
|
50 | + foreach ($files as $filename) { |
|
51 | 51 | $result = $fileCoupling->calculate($filename); |
52 | 52 | $this->collection->get($filename)->setLcom($result); |
53 | 53 | } |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | */ |
47 | 47 | public function __construct(OutputInterface $output, Aggregator $aggregator) |
48 | 48 | { |
49 | - $this->aggregator= $aggregator; |
|
49 | + $this->aggregator = $aggregator; |
|
50 | 50 | $this->output = $output; |
51 | 51 | } |
52 | 52 | |
@@ -66,12 +66,12 @@ discard block |
||
66 | 66 | $bounds = new Bounds(); |
67 | 67 | $instability = new Instability(); |
68 | 68 | |
69 | - foreach($groupedResults as $namespace => $results) { |
|
69 | + foreach ($groupedResults as $namespace => $results) { |
|
70 | 70 | |
71 | 71 | // we filter aggregates to conserve only direct results |
72 | 72 | $childs = new ResultCollection(); |
73 | - foreach($results as $r) { |
|
74 | - if($namespace === dirname($r->getName())) { |
|
73 | + foreach ($results as $r) { |
|
74 | + if ($namespace === dirname($r->getName())) { |
|
75 | 75 | $childs->push($r); |
76 | 76 | } |
77 | 77 | } |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | |
93 | 93 | $files = $this->finder->find($this->path); |
94 | 94 | |
95 | - if(0 == sizeof($files, COUNT_NORMAL)) { |
|
95 | + if (0 == sizeof($files, COUNT_NORMAL)) { |
|
96 | 96 | throw new \LogicException('No file found'); |
97 | 97 | } |
98 | 98 | |
@@ -116,12 +116,12 @@ discard block |
||
116 | 116 | , $classMap |
117 | 117 | ); |
118 | 118 | |
119 | - foreach($files as $k => $filename) { |
|
119 | + foreach ($files as $k => $filename) { |
|
120 | 120 | |
121 | 121 | $progress->advance(); |
122 | 122 | |
123 | 123 | // Integrity |
124 | - if(!$this->ignoreErrors && !$syntaxChecker->isCorrect($filename)) { |
|
124 | + if (!$this->ignoreErrors && !$syntaxChecker->isCorrect($filename)) { |
|
125 | 125 | $this->output->writeln(sprintf('<error>file %s is not valid and has been skipped</error>', $filename)); |
126 | 126 | unset($files[$k]); |
127 | 127 | continue; |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | // Analyze |
131 | 131 | try { |
132 | 132 | $resultSet = $fileAnalyzer->execute($filename); |
133 | - } catch(NoTokenizableException $e) { |
|
133 | + } catch (NoTokenizableException $e) { |
|
134 | 134 | $this->output->writeln(sprintf("<error>file %s has been skipped: \n%s</error>", $filename, $e->getMessage())); |
135 | 135 | unset($files[$k]); |
136 | 136 | continue; |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | $progress->finish(); |
152 | 152 | |
153 | 153 | |
154 | - if($this->withOOP) { |
|
154 | + if ($this->withOOP) { |
|
155 | 155 | // COUPLING (should be done after parsing files) |
156 | 156 | $this->output->write(str_pad("\x0DAnalyzing coupling. This will take few minutes...", 80, "\x20")); |
157 | 157 | $couplingAnalyzer = new CouplingAnalyzer($classMap, $collection); |
@@ -47,7 +47,7 @@ |
||
47 | 47 | * @inheritdoc |
48 | 48 | */ |
49 | 49 | public function execute(ResultCollection $collection, ResultCollection $aggregatedResults) { |
50 | - foreach($this->jobs as $job) { |
|
50 | + foreach ($this->jobs as $job) { |
|
51 | 51 | $job->execute($collection, $aggregatedResults); |
52 | 52 | } |
53 | 53 | } |
@@ -60,7 +60,7 @@ |
||
60 | 60 | * @inheritdoc |
61 | 61 | */ |
62 | 62 | public function execute(ResultCollection $collection, ResultCollection $aggregatedResults) { |
63 | - if(!$this->enabled) { |
|
63 | + if (!$this->enabled) { |
|
64 | 64 | return; |
65 | 65 | } |
66 | 66 |
@@ -61,12 +61,12 @@ |
||
61 | 61 | * @inheritdoc |
62 | 62 | */ |
63 | 63 | public function execute(ResultCollection $collection, ResultCollection $aggregatedResults) { |
64 | - if(!$this->destination) { |
|
64 | + if (!$this->destination) { |
|
65 | 65 | return; |
66 | 66 | } |
67 | 67 | |
68 | 68 | $dir = dirname($this->destination); |
69 | - if(!file_exists($dir)) { |
|
69 | + if (!file_exists($dir)) { |
|
70 | 70 | mkdir($dir, 0777, true); |
71 | 71 | } |
72 | 72 | $this->output->writeln(sprintf('Generating %s Report...', $this->formater->getName())); |
@@ -11,7 +11,6 @@ |
||
11 | 11 | use Hal\Application\Formater\FormaterInterface; |
12 | 12 | use Hal\Component\Result\ResultCollection; |
13 | 13 | use Symfony\Component\Console\Output\OutputInterface; |
14 | -use Symfony\Component\Console\Output\StreamOutput; |
|
15 | 14 | |
16 | 15 | |
17 | 16 | /** |