| Conditions | 16 |
| Paths | 90 |
| Total Lines | 48 |
| Code Lines | 36 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 35 | public function asArray(){ |
||
| 36 | $result=[]; |
||
| 37 | $prefix="";$httpMethods=false; |
||
| 38 | if($this->mainRouteClass){ |
||
| 39 | if(isset($this->mainRouteClass->path)) |
||
| 40 | $prefix=$this->mainRouteClass->path; |
||
| 41 | if(isset($this->mainRouteClass->methods)){ |
||
| 42 | $httpMethods=$this->mainRouteClass->methods; |
||
| 43 | if($httpMethods!==null){ |
||
| 44 | if(\is_string($httpMethods)) |
||
| 45 | $httpMethods=[$httpMethods]; |
||
| 46 | } |
||
| 47 | } |
||
| 48 | } |
||
| 49 | |||
| 50 | foreach ($this->routesMethods as $method=>$arrayAnnotsMethod){ |
||
| 51 | $routeAnnotations=$arrayAnnotsMethod["annotations"]; |
||
| 52 | foreach ($routeAnnotations as $routeAnnotation){ |
||
| 53 | if(isset($routeAnnotation->path)){ |
||
| 54 | $parameters=[]; |
||
| 55 | $path=$routeAnnotation->path; |
||
| 56 | preg_match_all('@\{(.+?)\}@s', $path, $matches); |
||
| 57 | if(isset($matches[1]) && \sizeof($matches[1])>0){ |
||
| 58 | $path=\preg_quote($path); |
||
| 59 | $params=Reflexion::getMethodParameters($arrayAnnotsMethod["method"]); |
||
| 60 | foreach ($matches[1] as $paramMatch){ |
||
| 61 | $find=\array_search($paramMatch, $params); |
||
| 62 | if($find!==false){ |
||
| 63 | $parameters[]=$find; |
||
| 64 | $path=\str_replace("\{".$paramMatch."\}", "(.+?)", $path); |
||
| 65 | }else{ |
||
| 66 | throw new \Exception("{$paramMatch} is not a parameter of the method ".$arrayAnnotsMethod["method"]->getName()); |
||
| 67 | } |
||
| 68 | } |
||
| 69 | } |
||
| 70 | $path=$this->cleanpath($prefix,$path)."$"; |
||
| 71 | if(isset($routeAnnotation->methods) && \is_array($routeAnnotation->methods)){ |
||
| 72 | $this->createRouteMethod($result,$path,$routeAnnotation->methods,$method,$routeAnnotation,$parameters); |
||
| 73 | }elseif(\is_array($httpMethods)){ |
||
| 74 | $this->createRouteMethod($result,$path,$httpMethods,$method,$routeAnnotation,$parameters); |
||
| 75 | }else{ |
||
| 76 | $result[$path]=["controller"=>$this->controllerClass,"action"=>$method,"parameters"=>$parameters]; |
||
| 77 | } |
||
| 78 | } |
||
| 79 | } |
||
| 80 | } |
||
| 81 | return $result; |
||
| 82 | } |
||
| 83 | |||
| 89 | } |