| Conditions | 10 |
| Paths | 321 |
| Total Lines | 135 |
| Code Lines | 77 |
| 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 |
||
| 71 | public function generateRest($ramlFile, Local $directoryOutput) |
||
| 72 | { |
||
| 73 | $parser = new Parser(); |
||
| 74 | try { |
||
| 75 | |||
| 76 | /* |
||
| 77 | * file di routing symfony |
||
| 78 | * @var array |
||
| 79 | */ |
||
| 80 | $routing = []; |
||
| 81 | |||
| 82 | /* |
||
| 83 | * Mappa delle proprieta dei controller da generare |
||
| 84 | * @var array |
||
| 85 | */ |
||
| 86 | $mappaClassDef = []; |
||
| 87 | |||
| 88 | $this->apiDef = $parser->parse($ramlFile); |
||
| 89 | $this->logger->info('Title: '.$this->apiDef->getTitle()); |
||
| 90 | |||
| 91 | $baseUrl = $this->apiDef->getBaseUrl(); |
||
| 92 | |||
| 93 | $parametriBaseUrl = $this->apiDef->getBaseUriParameters(); |
||
| 94 | /** @var \Raml\BaseUriParameter $definition */ |
||
| 95 | foreach ($parametriBaseUrl as $varName => $definition) { |
||
| 96 | if (!array_key_exists($varName, $this->mapExternalInfo)) { |
||
| 97 | $this->error('Missing: '.$varName.' -> '.$definition->getDescription()); |
||
| 98 | $this->mapExternalInfo[$varName] = 'undefined'; |
||
| 99 | } |
||
| 100 | $baseUrl = str_replace($varName, $this->mapExternalInfo[$varName], $baseUrl); |
||
| 101 | } |
||
| 102 | |||
| 103 | $this->info('BaseUrl '.$baseUrl); //corrisponde a host: "{subdomain}.example.com" dentro routing.yml |
||
| 104 | |||
| 105 | $enabledProtocols = $this->apiDef->getProtocols(); //serve per fare controlli su http/https -> schemes: [https] dentro routing.yml |
||
| 106 | |||
| 107 | $infoSecuritySchema = $this->apiDef->getSecuredBy(); // descrive i vari security schema usati nelle varie risorse |
||
| 108 | |||
| 109 | /* @var: \Raml\Resource[] */ |
||
| 110 | $resources = $this->apiDef->getResources(); |
||
| 111 | |||
| 112 | $namespace = $this->bundleName.'\Controller'; |
||
| 113 | |||
| 114 | /** @var: \Raml\Resource $resource */ |
||
| 115 | foreach ($resources as $resource) { |
||
| 116 | $displayName = $resource->getDisplayName(); |
||
| 117 | $this->info('Controller per path: '.$displayName); |
||
| 118 | |||
| 119 | $names = explode('/', $displayName); |
||
| 120 | preg_match_all("/(\/{[a-zA-Z]+}(\/)?)+/i", $displayName, $methodParam); |
||
| 121 | array_walk($names, [$this, 'removeGraph']); |
||
| 122 | $className = implode('', $names); |
||
| 123 | |||
| 124 | $methods = $resource->getMethods(); |
||
| 125 | |||
| 126 | if (count($methods) > 0) { |
||
| 127 | /** @var \Raml\Method $method */ |
||
| 128 | foreach ($methods as $method) { |
||
| 129 | $controllerName = ucfirst($className); |
||
| 130 | |||
| 131 | // Creo $appBundle / $workspace Controller . php |
||
| 132 | $this->info('Genera: '.$namespace.$controllerName.'Controller'); |
||
| 133 | $controllerProperties = []; |
||
| 134 | $controllerProperties['name'] = $controllerName.'Controller'; |
||
| 135 | $controllerProperties['namespace'] = $namespace; |
||
| 136 | $controllerProperties['extend'] = 'Symfony\Bundle\FrameworkBundle\Controller\Controller'; |
||
| 137 | |||
| 138 | $methodListParams = implode(',', $methodParam[0]); |
||
| 139 | |||
| 140 | $type = strtolower($method->getType()); |
||
| 141 | $methodCallName = $type.$controllerName; |
||
| 142 | $actionName = $methodCallName.'Action'; |
||
| 143 | $this->info('Call Method: '.$actionName.'('.$methodListParams.')'); |
||
| 144 | |||
| 145 | $controllerProperties['methods'] = []; |
||
| 146 | $controllerProperties['methods'][$actionName] = []; |
||
| 147 | $controllerProperties['methods'][$actionName]['params'] = [ |
||
| 148 | |||
| 149 | ]; |
||
| 150 | |||
| 151 | $description = $method->getDescription(); |
||
| 152 | $this->info('Description: '.$description); |
||
| 153 | |||
| 154 | $entryName = strtolower($className).'_'.$type; |
||
| 155 | $routing[$entryName]['path'] = $displayName; |
||
| 156 | $routing[$entryName]['defaults']['_controller'] = $this->bundleName.':'.$controllerName.':'.$methodCallName; |
||
| 157 | $routing[$entryName]['host'] = $baseUrl; |
||
| 158 | $routing[$entryName]['methods'] = []; |
||
| 159 | $routing[$entryName]['methods'][] = strtoupper($type); |
||
| 160 | $routing[$entryName]['schemas'] = $enabledProtocols; |
||
| 161 | $routing[$entryName]['requirements'] = []; |
||
| 162 | $routing[$entryName]['requirements'][] = 'FIXME'; |
||
| 163 | |||
| 164 | $mappaClassDef[$controllerName.'Controller'] = $controllerProperties; |
||
| 165 | } //fine methods |
||
| 166 | } |
||
| 167 | |||
| 168 | /* @var \Raml\Resource $subResources */ |
||
| 169 | $subResources = $resource->getResources(); |
||
| 170 | |||
| 171 | foreach ($subResources as $subResource) { |
||
| 172 | //$this->analyzeResource($subResource, $directoryOutput); |
||
| 173 | //// SAMPLE: |
||
| 174 | // /Workspace GET => Workspace/GetWorkspace.php |
||
| 175 | // /Workspace POST => Workspace/POSTWorkspace.php |
||
| 176 | // /Workspace/{id} GET => Workspace/GetWorkspaceById.php |
||
| 177 | } |
||
| 178 | } //fine reousrces |
||
| 179 | |||
| 180 | $indent = 4; |
||
| 181 | $inline = 2; |
||
| 182 | $yaml = new Dumper($indent); |
||
| 183 | $this->currentFile = $yaml->dump($routing, $inline, 0, 0); |
||
| 184 | |||
| 185 | $this->_createFileOnDir($directoryOutput, $this->bundleName.'/Resources/config/routing.yml'); |
||
| 186 | |||
| 187 | foreach ($mappaClassDef as $className => $controllerProp) { |
||
| 188 | $this->info('Devo creare '.$className); |
||
| 189 | $gClassgen = new ClassGenerator($namespace, $className); |
||
| 190 | $gClassgen->setLogger($this->logger); |
||
| 191 | $config = new ClassConfig(); |
||
| 192 | $typesReferenceArray = []; |
||
| 193 | $typesDescArray = []; |
||
| 194 | $gClassgen->generateClassType($controllerProp, $typesReferenceArray, $typesDescArray, $config); |
||
| 195 | $gClassgen->createFileOnDir($directoryOutput); |
||
| 196 | } |
||
| 197 | |||
| 198 | $this->info('Scrittura su '.$directoryOutput); |
||
| 199 | } catch (InvalidJsonException $e) { |
||
| 200 | $this->error('['.$e->getErrorCode().'] '.$e->getMessage()); |
||
| 201 | $this->error($e->getTraceAsString()); |
||
| 202 | } catch (RamlParserException $e) { |
||
| 203 | $this->error('['.$e->getErrorCode().'] '.$e->getMessage()); |
||
| 204 | } |
||
| 205 | } |
||
| 206 | } |
||
| 207 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.