@@ -14,9 +14,9 @@ discard block |
||
14 | 14 | */ |
15 | 15 | private static function searchPayloadParam($params, $variable) { |
16 | 16 | $exists = false; |
17 | - if(null !== $param && count($params)) { |
|
18 | - foreach($params as $param) { |
|
19 | - if($param['name'] === $variable) { |
|
17 | + if (null !== $param && count($params)) { |
|
18 | + foreach ($params as $param) { |
|
19 | + if ($param['name'] === $variable) { |
|
20 | 20 | $exists = true; |
21 | 21 | break; |
22 | 22 | } |
@@ -40,12 +40,12 @@ discard block |
||
40 | 40 | ]; |
41 | 41 | if ($endpoint['payload']['is_array']) { |
42 | 42 | $schema['items'] = [ |
43 | - '$ref' => '#/definitions/' . $endpoint['payload']['type'], |
|
43 | + '$ref' => '#/definitions/'.$endpoint['payload']['type'], |
|
44 | 44 | ]; |
45 | - } else { |
|
46 | - $schema['$ref'] = '#/definitions/' . $endpoint['payload']['type']; |
|
45 | + }else { |
|
46 | + $schema['$ref'] = '#/definitions/'.$endpoint['payload']['type']; |
|
47 | 47 | } |
48 | - if(!self::searchPayloadParam($paths[$url][$method]['parameters'], $endpoint['payload']['type'])) { |
|
48 | + if (!self::searchPayloadParam($paths[$url][$method]['parameters'], $endpoint['payload']['type'])) { |
|
49 | 49 | $paths[$url][$method]['parameters'][] = [ |
50 | 50 | 'in' => 'body', |
51 | 51 | 'name' => $endpoint['payload']['type'], |
@@ -74,18 +74,18 @@ discard block |
||
74 | 74 | if (array_key_exists('data', $endpoint['return']) && count(array_keys($object)) === count(array_keys($endpoint['return']['data']))) { |
75 | 75 | $classDefinition = [ |
76 | 76 | 'type' => 'object', |
77 | - '$ref' => '#/definitions/' . $class, |
|
77 | + '$ref' => '#/definitions/'.$class, |
|
78 | 78 | ]; |
79 | - } else { |
|
79 | + }else { |
|
80 | 80 | $classDefinition = [ |
81 | 81 | 'type' => 'array', |
82 | 82 | 'items' => [ |
83 | - '$ref' => '#/definitions/' . $class, |
|
83 | + '$ref' => '#/definitions/'.$class, |
|
84 | 84 | ], |
85 | 85 | ]; |
86 | 86 | } |
87 | 87 | |
88 | - if($paths[$url][$method]['responses'][200]['schema']['properties']['data']['type'] === 'boolean') { |
|
88 | + if ($paths[$url][$method]['responses'][200]['schema']['properties']['data']['type'] === 'boolean') { |
|
89 | 89 | $paths[$url][$method]['responses'][200]['schema']['properties']['data'] = $classDefinition; |
90 | 90 | } |
91 | 91 | $dtos += self::extractSwaggerDefinition($class, $object); |
@@ -163,18 +163,18 @@ discard block |
||
163 | 163 | ], |
164 | 164 | ]; |
165 | 165 | foreach ($fields as $field => $info) { |
166 | - if(array_key_exists('type', $info) || in_array($info['type'], ['array', 'object'])) { |
|
166 | + if (array_key_exists('type', $info) || in_array($info['type'], ['array', 'object'])) { |
|
167 | 167 | $definition[$name]['properties'][$field] = $info; |
168 | - } else { |
|
168 | + }else { |
|
169 | 169 | list($type, $format) = self::translateSwaggerFormats($info['type']); |
170 | 170 | $fieldData = [ |
171 | 171 | "type" => $type, |
172 | 172 | "required" => $info['required'], |
173 | 173 | ]; |
174 | - if(array_key_exists('description', $info)) { |
|
174 | + if (array_key_exists('description', $info)) { |
|
175 | 175 | $fieldData['description'] = $info['description']; |
176 | 176 | } |
177 | - if(array_key_exists('format', $info)) { |
|
177 | + if (array_key_exists('format', $info)) { |
|
178 | 178 | $fieldData['format'] = $info['format']; |
179 | 179 | } |
180 | 180 | $dto['properties'][$field] = $fieldData; |
@@ -57,10 +57,10 @@ discard block |
||
57 | 57 | if (!preg_match('/^ROOT/i', $module) && $module == $requestModule) { |
58 | 58 | $modules = [ |
59 | 59 | 'name' => $module, |
60 | - 'path' => realpath($info['template'] . DIRECTORY_SEPARATOR . '..'), |
|
60 | + 'path' => realpath($info['template'].DIRECTORY_SEPARATOR.'..'), |
|
61 | 61 | ]; |
62 | 62 | } |
63 | - } catch (\Exception $e) { |
|
63 | + }catch (\Exception $e) { |
|
64 | 64 | $modules[] = $e->getMessage(); |
65 | 65 | } |
66 | 66 | } |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | */ |
79 | 79 | public function extractApiEndpoints(array $module) |
80 | 80 | { |
81 | - $module_path = $module['path'] . DIRECTORY_SEPARATOR . 'Api'; |
|
81 | + $module_path = $module['path'].DIRECTORY_SEPARATOR.'Api'; |
|
82 | 82 | $module_name = $module['name']; |
83 | 83 | $endpoints = []; |
84 | 84 | if (file_exists($module_path)) { |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | if (count($finder)) { |
88 | 88 | /** @var \SplFileInfo $file */ |
89 | 89 | foreach ($finder as $file) { |
90 | - $namespace = "\\{$module_name}\\Api\\" . str_replace('.php', '', $file->getFilename()); |
|
90 | + $namespace = "\\{$module_name}\\Api\\".str_replace('.php', '', $file->getFilename()); |
|
91 | 91 | $info = $this->extractApiInfo($namespace, $module_name); |
92 | 92 | if (!empty($info)) { |
93 | 93 | $endpoints[$namespace] = $info; |
@@ -111,14 +111,14 @@ discard block |
||
111 | 111 | if (Router::exists($namespace) && !I18nHelper::checkI18Class($namespace)) { |
112 | 112 | $reflection = new \ReflectionClass($namespace); |
113 | 113 | $visible = InjectorHelper::checkIsVisible($reflection->getDocComment()); |
114 | - if($visible) { |
|
114 | + if ($visible) { |
|
115 | 115 | foreach ($reflection->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) { |
116 | 116 | try { |
117 | 117 | $mInfo = $this->extractMethodInfo($namespace, $method, $reflection, $module); |
118 | 118 | if (NULL !== $mInfo) { |
119 | 119 | $info[] = $mInfo; |
120 | 120 | } |
121 | - } catch (\Exception $e) { |
|
121 | + }catch (\Exception $e) { |
|
122 | 122 | Logger::getInstance()->errorLog($e->getMessage()); |
123 | 123 | } |
124 | 124 | } |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | $payload = $this->extractModelFields($namespace); |
252 | 252 | $reflector = new \ReflectionClass($namespace); |
253 | 253 | $shortName = $reflector->getShortName(); |
254 | - } else { |
|
254 | + }else { |
|
255 | 255 | $namespace = $model; |
256 | 256 | $shortName = $model; |
257 | 257 | } |
@@ -340,10 +340,10 @@ discard block |
||
340 | 340 | "required" => $field->isNotNull(), |
341 | 341 | 'format' => $format, |
342 | 342 | ]; |
343 | - if(count($field->getValueSet())) { |
|
343 | + if (count($field->getValueSet())) { |
|
344 | 344 | $info['enum'] = array_values($field->getValueSet()); |
345 | 345 | } |
346 | - if(null !== $field->getDefaultValue()) { |
|
346 | + if (null !== $field->getDefaultValue()) { |
|
347 | 347 | $info['default'] = $field->getDefaultValue(); |
348 | 348 | } |
349 | 349 | $payload[$field->getPhpName()] = $info; |
@@ -351,7 +351,7 @@ discard block |
||
351 | 351 | } elseif (null !== $reflector && $reflector->isSubclassOf(self::DTO_INTERFACE)) { |
352 | 352 | $payload = $this->extractDtoProperties($namespace); |
353 | 353 | } |
354 | - } catch (\Exception $e) { |
|
354 | + }catch (\Exception $e) { |
|
355 | 355 | Logger::getInstance()->errorLog($e->getMessage()); |
356 | 356 | } |
357 | 357 | |
@@ -382,7 +382,7 @@ discard block |
||
382 | 382 | $return = $this->extractReturn($modelNamespace, $docComments); |
383 | 383 | $url = array_pop($route); |
384 | 384 | $methodInfo = [ |
385 | - 'url' => str_replace("/" . $module . "/api", '', $url), |
|
385 | + 'url' => str_replace("/".$module."/api", '', $url), |
|
386 | 386 | 'method' => $info['http'], |
387 | 387 | 'description' => $info['label'], |
388 | 388 | 'return' => $return, |
@@ -393,7 +393,7 @@ discard block |
||
393 | 393 | $this->setRequestParams($method, $methodInfo, $modelNamespace, $docComments); |
394 | 394 | $this->setQueryParams($method, $methodInfo); |
395 | 395 | $this->setRequestHeaders($reflection, $methodInfo); |
396 | - } catch (\Exception $e) { |
|
396 | + }catch (\Exception $e) { |
|
397 | 397 | Logger::getInstance()->errorLog($e->getMessage()); |
398 | 398 | } |
399 | 399 | } |
@@ -462,10 +462,10 @@ discard block |
||
462 | 462 | $formatted = [ |
463 | 463 | "swagger" => "2.0", |
464 | 464 | "host" => preg_replace('/^(http|https)\:\/\/(.*)\/$/i', '$2', Router::getInstance()->getRoute('', true)), |
465 | - "basePath" => '/' . $module['name'] . '/api', |
|
465 | + "basePath" => '/'.$module['name'].'/api', |
|
466 | 466 | "schemes" => [Request::getInstance()->getServer('HTTPS') == 'on' ? "https" : "http"], |
467 | 467 | "info" => [ |
468 | - "title" => _('Documentación API módulo ') . $module['name'], |
|
468 | + "title" => _('Documentación API módulo ').$module['name'], |
|
469 | 469 | "version" => Config::getParam('api.version', '1.0.0'), |
470 | 470 | "contact" => [ |
471 | 471 | "name" => Config::getParam("author", "Fran López"), |
@@ -478,7 +478,7 @@ discard block |
||
478 | 478 | foreach ($endpoints as $model) { |
479 | 479 | foreach ($model as $endpoint) { |
480 | 480 | if (!preg_match('/^\/(admin|api)\//i', $endpoint['url']) && strlen($endpoint['url'])) { |
481 | - $url = preg_replace('/\/' . $module['name'] . '\/api/i', '', $endpoint['url']); |
|
481 | + $url = preg_replace('/\/'.$module['name'].'\/api/i', '', $endpoint['url']); |
|
482 | 482 | $description = $endpoint['description']; |
483 | 483 | $method = strtolower($endpoint['method']); |
484 | 484 | $paths[$url][$method] = [ |
@@ -539,7 +539,7 @@ discard block |
||
539 | 539 | protected function extractDtoName($dto, $isArray = false) |
540 | 540 | { |
541 | 541 | $dto = explode('\\', $dto); |
542 | - $modelDto = array_pop($dto) . "Dto"; |
|
542 | + $modelDto = array_pop($dto)."Dto"; |
|
543 | 543 | if ($isArray) { |
544 | 544 | $modelDto .= "List"; |
545 | 545 | } |
@@ -589,10 +589,10 @@ discard block |
||
589 | 589 | { |
590 | 590 | |
591 | 591 | $methodInfo['headers'] = []; |
592 | - foreach($reflection->getProperties() as $property) { |
|
592 | + foreach ($reflection->getProperties() as $property) { |
|
593 | 593 | $doc = $property->getDocComment(); |
594 | 594 | preg_match('/@header\ (.*)\n/i', $doc, $headers); |
595 | - if(count($headers)) { |
|
595 | + if (count($headers)) { |
|
596 | 596 | $header = [ |
597 | 597 | "name" => $headers[1], |
598 | 598 | "in" => "header", |
@@ -637,7 +637,7 @@ discard block |
||
637 | 637 | foreach ($method->getParameters() as $parameter) { |
638 | 638 | $parameterName = $parameter->getName(); |
639 | 639 | $types = []; |
640 | - preg_match_all('/\@param\ (.*)\ \$' . $parameterName . '$/im', $docComments, $types); |
|
640 | + preg_match_all('/\@param\ (.*)\ \$'.$parameterName.'$/im', $docComments, $types); |
|
641 | 641 | if (count($types) > 1) { |
642 | 642 | $methodInfo['parameters'][$parameterName] = $types[1][0]; |
643 | 643 | } |
@@ -659,21 +659,21 @@ discard block |
||
659 | 659 | $modelDto['objects'][$dtoName][$param] = [ |
660 | 660 | 'type' => 'array', |
661 | 661 | 'items' => [ |
662 | - '$ref' => '#/definitions/' . $info['type'], |
|
662 | + '$ref' => '#/definitions/'.$info['type'], |
|
663 | 663 | ] |
664 | 664 | ]; |
665 | - } else { |
|
665 | + }else { |
|
666 | 666 | $modelDto['objects'][$dtoName][$param] = [ |
667 | 667 | 'type' => 'object', |
668 | - '$ref' => '#/definitions/' . $info['type'], |
|
668 | + '$ref' => '#/definitions/'.$info['type'], |
|
669 | 669 | ]; |
670 | 670 | } |
671 | 671 | $modelDto['objects'][$info['class']] = $info['properties']; |
672 | 672 | $paramDto = $this->checkDtoAttributes($info['properties'], $info['properties'], $info['class']); |
673 | - if(array_key_exists('objects', $paramDto)) { |
|
673 | + if (array_key_exists('objects', $paramDto)) { |
|
674 | 674 | $modelDto['objects'] = array_merge($modelDto['objects'], $paramDto['objects']); |
675 | 675 | } |
676 | - } else { |
|
676 | + }else { |
|
677 | 677 | $modelDto['objects'][$dtoName][$param] = $info; |
678 | 678 | } |
679 | 679 | } |