Completed
Pull Request — master (#226)
by Oskar
03:03
created
src/Hal/Component/OOP/Extractor/AliasExtractor.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -43,9 +43,9 @@
 block discarded – undo
43 43
     {
44 44
         $alias = $real = null;
45 45
         $expression = $this->searcher->getUnder(array(';'), $n, $tokens);
46
-        if(preg_match('!use\s+(.*)\s+as\s+(.*)!i', $expression, $matches)) {
46
+        if (preg_match('!use\s+(.*)\s+as\s+(.*)!i', $expression, $matches)) {
47 47
             list(, $real, $alias) = $matches;
48
-        } else if(preg_match('!use\s+([^\s\(]+)\s*!i', $expression, $matches)) {
48
+        } else if (preg_match('!use\s+([^\s\(]+)\s*!i', $expression, $matches)) {
49 49
             list(, $real) = $matches;
50 50
             $alias = $real;
51 51
         }
Please login to merge, or discard this patch.
src/Hal/Component/OOP/Extractor/CallExtractor.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -52,12 +52,12 @@  discard block
 block discarded – undo
52 52
 
53 53
         $token = $tokens[$n];
54 54
         $call = null;
55
-        switch($token->getType()) {
55
+        switch ($token->getType()) {
56 56
             case T_PAAMAYIM_NEKUDOTAYIM:
57 57
                 $prev = $n - 1;
58 58
                 $value = $this->searcher->getUnder(array('::'), $prev, $tokens);
59 59
 
60
-                switch(true) {
60
+                switch (true) {
61 61
                     case $value == 'parent' && $this->currentClass:
62 62
                         return $this->currentClass->getParent();
63 63
 
@@ -66,10 +66,10 @@  discard block
 block discarded – undo
66 66
                         $extendPosition = $this->searcher->getExtendPosition($tokens, $n);
67 67
                         return $this->searcher->getFollowingName($extendPosition, $tokens);
68 68
 
69
-                    case ($value == 'static' ||$value === 'self')&& $this->currentClass:
69
+                    case ($value == 'static' || $value === 'self') && $this->currentClass:
70 70
                         return $this->currentClass->getFullname();
71 71
 
72
-                    case ($value == 'static' ||$value === 'self'):
72
+                    case ($value == 'static' || $value === 'self'):
73 73
                         $extendPosition = $this->searcher->getClassNamePosition($tokens);
74 74
                         return $this->searcher->getFollowingName($extendPosition, $tokens);
75 75
 
@@ -79,12 +79,12 @@  discard block
 block discarded – undo
79 79
 
80 80
             case T_NEW:
81 81
                 $call = $this->searcher->getFollowingName($n, $tokens);
82
-                if(preg_match('!^(\w+)!', $call, $matches)) { // fixes PHP 5.4:    (new MyClass)->foo()
82
+                if (preg_match('!^(\w+)!', $call, $matches)) { // fixes PHP 5.4:    (new MyClass)->foo()
83 83
                     $call = $matches[1];
84 84
                 }
85 85
                 break;
86 86
         }
87
-        if(null === $call) {
87
+        if (null === $call) {
88 88
             throw new \LogicException('Classname of call not found');
89 89
         }
90 90
         return $call;
Please login to merge, or discard this patch.
src/Hal/Component/OOP/Extractor/ClassExtractor.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -49,7 +49,7 @@
 block discarded – undo
49 49
     {
50 50
         // is PHP7 ?
51 51
         $previous = $tokens->get($n - 2);
52
-        if($previous && T_NEW === $previous->getType()) {
52
+        if ($previous && T_NEW === $previous->getType()) {
53 53
             // anonymous class
54 54
             $class = new ReflectedAnonymousClass($this->namespace, 'class@anonymous');
55 55
             return $class;
Please login to merge, or discard this patch.
src/Hal/Component/OOP/Extractor/ClassMap.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@
 block discarded – undo
31 31
      * @return $this
32 32
      */
33 33
     public function push($filename, Result $result) {
34
-        $this->classes[$filename] = $result;;
34
+        $this->classes[$filename] = $result; ;
35 35
         return $this;
36 36
     }
37 37
 
Please login to merge, or discard this patch.
src/Hal/Component/OOP/Extractor/MethodExtractor.php 1 patch
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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;
Please login to merge, or discard this patch.
src/Hal/Component/OOP/Extractor/Result.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
     public function asArray() {
32 32
 
33 33
         $nom = 0;
34
-        foreach($this->getClasses() as $class) {
34
+        foreach ($this->getClasses() as $class) {
35 35
             $nom += sizeof($class->getMethods(), COUNT_NORMAL);
36 36
         }
37 37
 
@@ -71,8 +71,8 @@  discard block
 block discarded – undo
71 71
      */
72 72
     public function getAbstractClasses() {
73 73
         $result = array();
74
-        foreach($this->getClasses() as $class) {
75
-            if($class->isAbstract() ||$class instanceof ReflectedInterface) {
74
+        foreach ($this->getClasses() as $class) {
75
+            if ($class->isAbstract() || $class instanceof ReflectedInterface) {
76 76
                 array_push($result, $class);
77 77
             }
78 78
         }
@@ -86,8 +86,8 @@  discard block
 block discarded – undo
86 86
      */
87 87
     public function getAnonymousClasses() {
88 88
         $result = array();
89
-        foreach($this->getClasses() as $class) {
90
-            if($class instanceof ReflectedClass\ReflectedAnonymousClass) {
89
+        foreach ($this->getClasses() as $class) {
90
+            if ($class instanceof ReflectedClass\ReflectedAnonymousClass) {
91 91
                 array_push($result, $class);
92 92
             }
93 93
         }
@@ -101,8 +101,8 @@  discard block
 block discarded – undo
101 101
      */
102 102
     public function getInterfaces() {
103 103
         $result = array();
104
-        foreach($this->getClasses() as $class) {
105
-            if($class instanceof ReflectedInterface) {
104
+        foreach ($this->getClasses() as $class) {
105
+            if ($class instanceof ReflectedInterface) {
106 106
                 array_push($result, $class);
107 107
             }
108 108
         }
@@ -116,8 +116,8 @@  discard block
 block discarded – undo
116 116
      */
117 117
     public function getConcreteClasses() {
118 118
         $result = array();
119
-        foreach($this->getClasses() as $class) {
120
-            if(!$class->isAbstract() &&!$class instanceof ReflectedInterface  && !$class instanceof ReflectedClass\ReflectedAnonymousClass) {
119
+        foreach ($this->getClasses() as $class) {
120
+            if (!$class->isAbstract() && !$class instanceof ReflectedInterface && !$class instanceof ReflectedClass\ReflectedAnonymousClass) {
121 121
                 array_push($result, $class);
122 122
             }
123 123
         }
Please login to merge, or discard this patch.
src/Hal/Component/OOP/Reflected/ReflectedClass.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -136,11 +136,11 @@  discard block
 block discarded – undo
136 136
     public function getDependencies()
137 137
     {
138 138
         $dependencies = array();
139
-        foreach($this->getMethods() as $method) {
139
+        foreach ($this->getMethods() as $method) {
140 140
             $dependencies = array_merge($dependencies, $method->getDependencies());
141 141
         }
142
-        foreach($dependencies as &$name) {
143
-            if(in_array($name, array('self', 'static'))) {
142
+        foreach ($dependencies as &$name) {
143
+            if (in_array($name, array('self', 'static'))) {
144 144
                 $name = $this->getFullname();
145 145
             }
146 146
             $name = $this->nameResolver->resolve($name, $this->namespace);
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
     public function getInterfaces()
208 208
     {
209 209
         $resolvedInterfaces = array();
210
-        foreach($this->interfaces as $interface) {
210
+        foreach ($this->interfaces as $interface) {
211 211
             array_push($resolvedInterfaces, $this->nameResolver->resolve($interface, $this->namespace));
212 212
         }
213 213
         return $resolvedInterfaces;
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
      */
231 231
     public function getAnonymousClasses() {
232 232
         $result = array();
233
-        foreach($this->methods as $method) {
233
+        foreach ($this->methods as $method) {
234 234
             $result = array_merge($result, $method->getAnonymousClasses());
235 235
         }
236 236
         return $result;
Please login to merge, or discard this patch.
src/Hal/Component/OOP/Reflected/ReflectedMethod.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -189,10 +189,10 @@  discard block
 block discarded – undo
189 189
         // on read : compare with aliases. We cannot make it in pushDependency() => aliases aren't yet known
190 190
         $result = array();
191 191
         $resolver = new TypeResolver();
192
-        foreach($this->returns as $return) {
192
+        foreach ($this->returns as $return) {
193 193
             $type = $this->nameResolver->resolve($return->getType(), null);
194 194
 
195
-            if("\\" !== $type[0] &&!$resolver->isNative($type)) {
195
+            if ("\\" !== $type[0] && !$resolver->isNative($type)) {
196 196
                 $type = $this->namespace.'\\'.$type;
197 197
             }
198 198
 
@@ -233,21 +233,21 @@  discard block
 block discarded – undo
233 233
     {
234 234
         // on read : compare with aliases. We cannot make it in pushDependency() => aliases aren't yet known
235 235
         $dependencies = array();
236
-        foreach($this->dependencies as $name) {
236
+        foreach ($this->dependencies as $name) {
237 237
             array_push($dependencies, $this->nameResolver->resolve($name, null));
238 238
         }
239 239
 
240 240
         // returned values
241 241
         $resolver = new TypeResolver();
242
-        foreach($this->returns as $return) {
242
+        foreach ($this->returns as $return) {
243 243
             $name = $return->getType();
244
-            if(!$resolver->isNative($name)) {
244
+            if (!$resolver->isNative($name)) {
245 245
                 array_push($dependencies, $this->nameResolver->resolve($name, null));
246 246
             }
247 247
         }
248 248
 
249 249
         // anonymous classes in method (inner class)
250
-        foreach($this->anonymousClasses as $c) {
250
+        foreach ($this->anonymousClasses as $c) {
251 251
             array_push($dependencies, $c->getParent());
252 252
             $dependencies = array_merge($dependencies, $c->getDependencies());
253 253
         }
@@ -379,7 +379,7 @@  discard block
 block discarded – undo
379 379
     public function getInstanciedClasses()
380 380
     {
381 381
         $classes = array();
382
-        foreach($this->instanciedClasses as $name) {
382
+        foreach ($this->instanciedClasses as $name) {
383 383
             array_push($classes, $this->nameResolver->resolve($name, null));
384 384
         }
385 385
         return $classes;
Please login to merge, or discard this patch.
src/Hal/Component/OOP/Resolver/NameResolver.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -43,7 +43,7 @@
 block discarded – undo
43 43
         }
44 44
 
45 45
         // anonymous class
46
-        if('class@anonymous' == $name ) {
46
+        if ('class@anonymous' == $name) {
47 47
             return $name;
48 48
         }
49 49
 
Please login to merge, or discard this patch.