| Conditions | 10 |
| Paths | 18 |
| Total Lines | 55 |
| 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 |
||
| 101 | public function createInterface(string $name, string $returntype):bool{ |
||
| 102 | $interfaceName = $name.'Interface'; |
||
| 103 | |||
| 104 | $str = '<?php'.PHP_EOL.PHP_EOL |
||
| 105 | .'namespace '.__NAMESPACE__.';'.PHP_EOL.PHP_EOL |
||
| 106 | .'use \\'.$returntype.';'.PHP_EOL.PHP_EOL |
||
| 107 | .'interface '.$interfaceName.'{'.PHP_EOL.PHP_EOL; |
||
| 108 | |||
| 109 | foreach($this->endpointMap->toArray() as $methodName => $params){ |
||
| 110 | |||
| 111 | if($methodName === 'API_BASE'){ |
||
| 112 | continue; |
||
| 113 | } |
||
| 114 | |||
| 115 | $args = []; |
||
| 116 | $str.= "\t".'/**'.PHP_EOL; |
||
| 117 | |||
| 118 | if(is_array($params['path_elements']) && count($params['path_elements']) > 0){ |
||
| 119 | |||
| 120 | foreach($params['path_elements'] as $i){ |
||
| 121 | $a = 'string $'.$i; |
||
| 122 | $str.= "\t".' * @param '.$a.PHP_EOL; |
||
| 123 | |||
| 124 | $args[] = $a; |
||
| 125 | } |
||
| 126 | |||
| 127 | } |
||
| 128 | |||
| 129 | if(!empty($params['query'])){ |
||
| 130 | $a = 'array $params = [\''.implode('\', \'', $params['query']).'\']'; |
||
| 131 | $str.= "\t".' * @param '.$a.PHP_EOL; |
||
| 132 | $args[] = $a; |
||
| 133 | } |
||
| 134 | |||
| 135 | if(in_array($params['method'], ['PATCH', 'POST', 'PUT', 'DELETE'])){ |
||
| 136 | |||
| 137 | if($params['body'] !== null){ |
||
| 138 | $a = is_array($params['body']) ? 'array $body = [\''.implode('\', \'', $params['body']).'\']' : 'array $body = []'; |
||
| 139 | $str.= "\t".' * @param '.$a.PHP_EOL; |
||
| 140 | $args[] = $a; |
||
| 141 | } |
||
| 142 | |||
| 143 | } |
||
| 144 | |||
| 145 | $r = new ReflectionClass($returntype); |
||
| 146 | |||
| 147 | $str.= "\t".' * @return \\'.$r->getName().PHP_EOL; |
||
| 148 | $str.= "\t".' */'.PHP_EOL; |
||
| 149 | $str.= "\t".'public function '.$methodName.'('.implode(', ', $args).'):'.$r->getShortName().';'.PHP_EOL.PHP_EOL; |
||
| 150 | } |
||
| 151 | |||
| 152 | $str .= '}'.PHP_EOL; |
||
| 153 | |||
| 154 | return (bool)file_put_contents(dirname((new ReflectionClass($this->provider))->getFileName()).'/'.$interfaceName.'.php', $str); |
||
| 155 | } |
||
| 156 | |||
| 158 |