@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | * @param $object |
48 | 48 | * @param $paths |
49 | 49 | * @param $url |
50 | - * @param $method |
|
50 | + * @param string $method |
|
51 | 51 | * @param $dtos |
52 | 52 | * @param $isReturn |
53 | 53 | * @return array |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | * Translator from php types to swagger types |
88 | 88 | * @param string $format |
89 | 89 | * |
90 | - * @return array |
|
90 | + * @return string[] |
|
91 | 91 | */ |
92 | 92 | public static function translateSwaggerFormats($format) |
93 | 93 | { |
@@ -27,10 +27,10 @@ discard block |
||
27 | 27 | ]; |
28 | 28 | if ($endpoint['payload']['is_array']) { |
29 | 29 | $schema['items'] = [ |
30 | - '$ref' => '#/definitions/' . $endpoint['payload']['type'], |
|
30 | + '$ref' => '#/definitions/'.$endpoint['payload']['type'], |
|
31 | 31 | ]; |
32 | - } else { |
|
33 | - $schema['$ref'] = '#/definitions/' . $endpoint['payload']['type']; |
|
32 | + }else { |
|
33 | + $schema['$ref'] = '#/definitions/'.$endpoint['payload']['type']; |
|
34 | 34 | } |
35 | 35 | $paths[$url][$method]['parameters'][] = [ |
36 | 36 | 'in' => 'body', |
@@ -59,18 +59,18 @@ discard block |
||
59 | 59 | if (array_key_exists('data', $endpoint['return']) && count(array_keys($object)) === count(array_keys($endpoint['return']['data']))) { |
60 | 60 | $classDefinition = [ |
61 | 61 | 'type' => 'object', |
62 | - '$ref' => '#/definitions/' . $class, |
|
62 | + '$ref' => '#/definitions/'.$class, |
|
63 | 63 | ]; |
64 | - } else { |
|
64 | + }else { |
|
65 | 65 | $classDefinition = [ |
66 | 66 | 'type' => 'array', |
67 | 67 | 'items' => [ |
68 | - '$ref' => '#/definitions/' . $class, |
|
68 | + '$ref' => '#/definitions/'.$class, |
|
69 | 69 | ], |
70 | 70 | ]; |
71 | 71 | } |
72 | 72 | |
73 | - if($paths[$url][$method]['responses'][200]['schema']['properties']['data']['type'] === 'boolean') { |
|
73 | + if ($paths[$url][$method]['responses'][200]['schema']['properties']['data']['type'] === 'boolean') { |
|
74 | 74 | $paths[$url][$method]['responses'][200]['schema']['properties']['data'] = $classDefinition; |
75 | 75 | } |
76 | 76 | $dtos += self::extractSwaggerDefinition($class, $object); |
@@ -148,18 +148,18 @@ discard block |
||
148 | 148 | ], |
149 | 149 | ]; |
150 | 150 | foreach ($fields as $field => $info) { |
151 | - if(array_key_exists('type', $info) || in_array($info['type'], ['array', 'object'])) { |
|
151 | + if (array_key_exists('type', $info) || in_array($info['type'], ['array', 'object'])) { |
|
152 | 152 | $definition[$name]['properties'][$field] = $info; |
153 | - } else { |
|
153 | + }else { |
|
154 | 154 | list($type, $format) = self::translateSwaggerFormats($info['type']); |
155 | 155 | $fieldData = [ |
156 | 156 | "type" => $type, |
157 | 157 | "required" => $info['required'], |
158 | 158 | ]; |
159 | - if(array_key_exists('description', $info)) { |
|
159 | + if (array_key_exists('description', $info)) { |
|
160 | 160 | $fieldData['description'] = $info['description']; |
161 | 161 | } |
162 | - if(array_key_exists('format', $info)) { |
|
162 | + if (array_key_exists('format', $info)) { |
|
163 | 163 | $fieldData['format'] = $info['format']; |
164 | 164 | } |
165 | 165 | $dto['properties'][$field] = $fieldData; |
@@ -3,7 +3,6 @@ |
||
3 | 3 | |
4 | 4 | use PSFS\base\Logger; |
5 | 5 | use PSFS\base\Router; |
6 | -use PSFS\services\DocumentorService; |
|
7 | 6 | |
8 | 7 | /** |
9 | 8 | * Class InjectorHelper |
@@ -27,10 +27,10 @@ discard block |
||
27 | 27 | $isRequired = self::checkIsRequired($property->getDocComment()); |
28 | 28 | $label = self::getLabel($property->getDocComment()); |
29 | 29 | $isArray = (bool)preg_match('/\[\]$/', $instanceType); |
30 | - if($isArray) { |
|
30 | + if ($isArray) { |
|
31 | 31 | $instanceType = str_replace('[]', '', $instanceType); |
32 | 32 | } |
33 | - if(!Router::exists($instanceType) || $instanceType === '\\DateTime') { |
|
33 | + if (!Router::exists($instanceType) || $instanceType === '\\DateTime') { |
|
34 | 34 | list($type, $format) = DocumentorHelper::translateSwaggerFormats($instanceType); |
35 | 35 | $variables[$property->getName()] = [ |
36 | 36 | 'type' => $type, |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | 'required' => $isRequired, |
39 | 39 | 'description' => $label, |
40 | 40 | ]; |
41 | - } else { |
|
41 | + }else { |
|
42 | 42 | $instance = new \ReflectionClass($instanceType); |
43 | 43 | $variables[$property->getName()] = [ |
44 | 44 | 'is_array' => $isArray, |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | // Extract description |
125 | 125 | $label = null; |
126 | 126 | preg_match('/@label\ (.*)\n/i', $doc, $matches); |
127 | - if(count($matches)) { |
|
127 | + if (count($matches)) { |
|
128 | 128 | $label = _($matches[1]); |
129 | 129 | } |
130 | 130 | return $label; |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | public static function getDefaultValue($doc) { |
138 | 138 | $default = null; |
139 | 139 | preg_match('/@default\ (.*)\n/i', $doc, $matches); |
140 | - if(count($matches)) { |
|
140 | + if (count($matches)) { |
|
141 | 141 | $default = $matches[1]; |
142 | 142 | } |
143 | 143 | return $default; |
@@ -153,13 +153,13 @@ discard block |
||
153 | 153 | */ |
154 | 154 | public static function constructInyectableInstance($variable, $singleton, $classNameSpace, $calledClass) |
155 | 155 | { |
156 | - Logger::log('Create inyectable instance for ' . $classNameSpace); |
|
156 | + Logger::log('Create inyectable instance for '.$classNameSpace); |
|
157 | 157 | $reflector = new \ReflectionClass($calledClass); |
158 | 158 | $property = $reflector->getProperty($variable); |
159 | 159 | $varInstanceType = (null === $classNameSpace) ? InjectorHelper::extractVarType($property->getDocComment()) : $classNameSpace; |
160 | 160 | if (true === $singleton && method_exists($varInstanceType, "getInstance")) { |
161 | 161 | $instance = $varInstanceType::getInstance(); |
162 | - } else { |
|
162 | + }else { |
|
163 | 163 | $instance = new $varInstanceType(); |
164 | 164 | } |
165 | 165 | return $instance; |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | public static function getClassProperties($class) |
174 | 174 | { |
175 | 175 | $properties = []; |
176 | - Logger::log('Extracting annotations properties from class ' . $class); |
|
176 | + Logger::log('Extracting annotations properties from class '.$class); |
|
177 | 177 | $selfReflector = new \ReflectionClass($class); |
178 | 178 | if (false !== $selfReflector->getParentClass()) { |
179 | 179 | $properties = self::getClassProperties($selfReflector->getParentClass()->getName()); |
@@ -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 | $namespace = $reflector->getShortName(); |
254 | - } else { |
|
254 | + }else { |
|
255 | 255 | $namespace = $model; |
256 | 256 | } |
257 | 257 | |
@@ -339,10 +339,10 @@ discard block |
||
339 | 339 | "required" => $field->isNotNull(), |
340 | 340 | 'format' => $format, |
341 | 341 | ]; |
342 | - if(count($field->getValueSet())) { |
|
342 | + if (count($field->getValueSet())) { |
|
343 | 343 | $info['enum'] = array_values($field->getValueSet()); |
344 | 344 | } |
345 | - if(null !== $field->getDefaultValue()) { |
|
345 | + if (null !== $field->getDefaultValue()) { |
|
346 | 346 | $info['default'] = $field->getDefaultValue(); |
347 | 347 | } |
348 | 348 | $payload[$field->getPhpName()] = $info; |
@@ -350,7 +350,7 @@ discard block |
||
350 | 350 | } elseif (null !== $reflector && $reflector->isSubclassOf(self::DTO_INTERFACE)) { |
351 | 351 | $payload = $this->extractDtoProperties($namespace); |
352 | 352 | } |
353 | - } catch (\Exception $e) { |
|
353 | + }catch (\Exception $e) { |
|
354 | 354 | Logger::getInstance()->errorLog($e->getMessage()); |
355 | 355 | } |
356 | 356 | |
@@ -381,7 +381,7 @@ discard block |
||
381 | 381 | $return = $this->extractReturn($modelNamespace, $docComments); |
382 | 382 | $url = array_pop($route); |
383 | 383 | $methodInfo = [ |
384 | - 'url' => str_replace("/" . $module . "/api", '', $url), |
|
384 | + 'url' => str_replace("/".$module."/api", '', $url), |
|
385 | 385 | 'method' => $info['http'], |
386 | 386 | 'description' => $info['label'], |
387 | 387 | 'return' => $return, |
@@ -392,7 +392,7 @@ discard block |
||
392 | 392 | $this->setRequestParams($method, $methodInfo, $modelNamespace, $docComments); |
393 | 393 | $this->setQueryParams($method, $methodInfo); |
394 | 394 | $this->setRequestHeaders($reflection, $methodInfo); |
395 | - } catch (\Exception $e) { |
|
395 | + }catch (\Exception $e) { |
|
396 | 396 | Logger::getInstance()->errorLog($e->getMessage()); |
397 | 397 | } |
398 | 398 | } |
@@ -461,10 +461,10 @@ discard block |
||
461 | 461 | $formatted = [ |
462 | 462 | "swagger" => "2.0", |
463 | 463 | "host" => preg_replace('/^(http|https)\:\/\/(.*)\/$/i', '$2', Router::getInstance()->getRoute('', true)), |
464 | - "basePath" => '/' . $module['name'] . '/api', |
|
464 | + "basePath" => '/'.$module['name'].'/api', |
|
465 | 465 | "schemes" => [Request::getInstance()->getServer('HTTPS') == 'on' ? "https" : "http"], |
466 | 466 | "info" => [ |
467 | - "title" => _('Documentación API módulo ') . $module['name'], |
|
467 | + "title" => _('Documentación API módulo ').$module['name'], |
|
468 | 468 | "version" => Config::getParam('api.version', '1.0.0'), |
469 | 469 | "contact" => [ |
470 | 470 | "name" => Config::getParam("author", "Fran López"), |
@@ -477,7 +477,7 @@ discard block |
||
477 | 477 | foreach ($endpoints as $model) { |
478 | 478 | foreach ($model as $endpoint) { |
479 | 479 | if (!preg_match('/^\/(admin|api)\//i', $endpoint['url']) && strlen($endpoint['url'])) { |
480 | - $url = preg_replace('/\/' . $module['name'] . '\/api/i', '', $endpoint['url']); |
|
480 | + $url = preg_replace('/\/'.$module['name'].'\/api/i', '', $endpoint['url']); |
|
481 | 481 | $description = $endpoint['description']; |
482 | 482 | $method = strtolower($endpoint['method']); |
483 | 483 | $paths[$url][$method] = [ |
@@ -538,7 +538,7 @@ discard block |
||
538 | 538 | protected function extractDtoName($dto, $isArray = false) |
539 | 539 | { |
540 | 540 | $dto = explode('\\', $dto); |
541 | - $modelDto = array_pop($dto) . "Dto"; |
|
541 | + $modelDto = array_pop($dto)."Dto"; |
|
542 | 542 | if ($isArray) { |
543 | 543 | $modelDto .= "List"; |
544 | 544 | } |
@@ -588,10 +588,10 @@ discard block |
||
588 | 588 | { |
589 | 589 | |
590 | 590 | $methodInfo['headers'] = []; |
591 | - foreach($reflection->getProperties() as $property) { |
|
591 | + foreach ($reflection->getProperties() as $property) { |
|
592 | 592 | $doc = $property->getDocComment(); |
593 | 593 | preg_match('/@header\ (.*)\n/i', $doc, $headers); |
594 | - if(count($headers)) { |
|
594 | + if (count($headers)) { |
|
595 | 595 | $header = [ |
596 | 596 | "name" => $headers[1], |
597 | 597 | "in" => "header", |
@@ -635,7 +635,7 @@ discard block |
||
635 | 635 | foreach ($method->getParameters() as $parameter) { |
636 | 636 | $parameterName = $parameter->getName(); |
637 | 637 | $types = []; |
638 | - preg_match_all('/\@param\ (.*)\ \$' . $parameterName . '$/im', $docComments, $types); |
|
638 | + preg_match_all('/\@param\ (.*)\ \$'.$parameterName.'$/im', $docComments, $types); |
|
639 | 639 | if (count($types) > 1) { |
640 | 640 | $methodInfo['parameters'][$parameterName] = $types[1][0]; |
641 | 641 | } |
@@ -657,21 +657,21 @@ discard block |
||
657 | 657 | $modelDto['objects'][$dtoName][$param] = [ |
658 | 658 | 'type' => 'array', |
659 | 659 | 'items' => [ |
660 | - '$ref' => '#/definitions/' . $info['shortName'], |
|
660 | + '$ref' => '#/definitions/'.$info['shortName'], |
|
661 | 661 | ] |
662 | 662 | ]; |
663 | - } else { |
|
663 | + }else { |
|
664 | 664 | $modelDto['objects'][$dtoName][$param] = [ |
665 | 665 | 'type' => 'object', |
666 | - '$ref' => '#/definitions/' . $info['shortName'], |
|
666 | + '$ref' => '#/definitions/'.$info['shortName'], |
|
667 | 667 | ]; |
668 | 668 | } |
669 | 669 | $modelDto['objects'][$info['class']] = $info['variables']; |
670 | 670 | $paramDto = $this->checkDtoAttributes($info['variables'], $info['variables'], $info['class']); |
671 | - if(array_key_exists('objects', $paramDto)) { |
|
671 | + if (array_key_exists('objects', $paramDto)) { |
|
672 | 672 | $modelDto['objects'] = array_merge($modelDto['objects'], $paramDto['objects']); |
673 | 673 | } |
674 | - } else { |
|
674 | + }else { |
|
675 | 675 | $modelDto['objects'][$dtoName][$param] = $info; |
676 | 676 | } |
677 | 677 | } |