@@ -72,8 +72,8 @@ discard block |
||
| 72 | 72 | |
| 73 | 73 | /** |
| 74 | 74 | * Method extract if a variable is required |
| 75 | - * @param $doc |
|
| 76 | - * @return null|string |
|
| 75 | + * @param string $doc |
|
| 76 | + * @return boolean |
|
| 77 | 77 | */ |
| 78 | 78 | public static function checkIsRequired($doc) |
| 79 | 79 | { |
@@ -86,8 +86,8 @@ discard block |
||
| 86 | 86 | |
| 87 | 87 | /** |
| 88 | 88 | * Method extract if a class or variable is visible |
| 89 | - * @param $doc |
|
| 90 | - * @return null|string |
|
| 89 | + * @param string $doc |
|
| 90 | + * @return boolean |
|
| 91 | 91 | */ |
| 92 | 92 | public static function checkIsVisible($doc) |
| 93 | 93 | { |
@@ -23,10 +23,10 @@ discard block |
||
| 23 | 23 | */ |
| 24 | 24 | public function json($response, $statusCode = 200) |
| 25 | 25 | { |
| 26 | - if(Config::getParam('profiling.enable')) { |
|
| 27 | - if(is_array($response)) { |
|
| 26 | + if (Config::getParam('profiling.enable')) { |
|
| 27 | + if (is_array($response)) { |
|
| 28 | 28 | $response['profiling'] = Inspector::getStats(); |
| 29 | - } elseif($response instanceof JsonResponse) { |
|
| 29 | + } elseif ($response instanceof JsonResponse) { |
|
| 30 | 30 | $response = ProfilingJsonResponse::createFromPrevious($response, Inspector::getStats()); |
| 31 | 31 | } |
| 32 | 32 | } |
@@ -34,13 +34,13 @@ discard block |
||
| 34 | 34 | $this->decodeJsonReponse($response); |
| 35 | 35 | |
| 36 | 36 | $mask = JSON_UNESCAPED_UNICODE | JSON_BIGINT_AS_STRING; |
| 37 | - if(Config::getParam('output.json.strict_numbers')) { |
|
| 37 | + if (Config::getParam('output.json.strict_numbers')) { |
|
| 38 | 38 | $mask = JSON_UNESCAPED_UNICODE | JSON_BIGINT_AS_STRING | JSON_NUMERIC_CHECK; |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | $data = json_encode($response, $mask); |
| 42 | - if(Config::getParam('angular.protection', false)) { |
|
| 43 | - $data = ")]}',\n" . $data; |
|
| 42 | + if (Config::getParam('angular.protection', false)) { |
|
| 43 | + $data = ")]}',\n".$data; |
|
| 44 | 44 | } |
| 45 | 45 | $this->setStatus($statusCode); |
| 46 | 46 | ResponseHelper::setDebugHeaders([]); |
@@ -55,10 +55,10 @@ discard block |
||
| 55 | 55 | if (!preg_match('/^ROOT/i', $module) && $module == $requestModule) { |
| 56 | 56 | $modules = [ |
| 57 | 57 | 'name' => $module, |
| 58 | - 'path' => realpath($info['template'] . DIRECTORY_SEPARATOR . '..'), |
|
| 58 | + 'path' => realpath($info['template'].DIRECTORY_SEPARATOR.'..'), |
|
| 59 | 59 | ]; |
| 60 | 60 | } |
| 61 | - } catch (\Exception $e) { |
|
| 61 | + }catch (\Exception $e) { |
|
| 62 | 62 | $modules[] = $e->getMessage(); |
| 63 | 63 | } |
| 64 | 64 | } |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | */ |
| 77 | 77 | public function extractApiEndpoints(array $module) |
| 78 | 78 | { |
| 79 | - $module_path = $module['path'] . DIRECTORY_SEPARATOR . 'Api'; |
|
| 79 | + $module_path = $module['path'].DIRECTORY_SEPARATOR.'Api'; |
|
| 80 | 80 | $module_name = $module['name']; |
| 81 | 81 | $endpoints = []; |
| 82 | 82 | if (file_exists($module_path)) { |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | if (count($finder)) { |
| 86 | 86 | /** @var \SplFileInfo $file */ |
| 87 | 87 | foreach ($finder as $file) { |
| 88 | - $namespace = "\\{$module_name}\\Api\\" . str_replace('.php', '', $file->getFilename()); |
|
| 88 | + $namespace = "\\{$module_name}\\Api\\".str_replace('.php', '', $file->getFilename()); |
|
| 89 | 89 | $info = $this->extractApiInfo($namespace, $module_name); |
| 90 | 90 | if (!empty($info)) { |
| 91 | 91 | $endpoints[$namespace] = $info; |
@@ -109,14 +109,14 @@ discard block |
||
| 109 | 109 | if (Router::exists($namespace) && !I18nHelper::checkI18Class($namespace)) { |
| 110 | 110 | $reflection = new \ReflectionClass($namespace); |
| 111 | 111 | $visible = InjectorHelper::checkIsVisible($reflection->getDocComment()); |
| 112 | - if($visible) { |
|
| 112 | + if ($visible) { |
|
| 113 | 113 | foreach ($reflection->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) { |
| 114 | 114 | try { |
| 115 | 115 | $mInfo = $this->extractMethodInfo($namespace, $method, $reflection, $module); |
| 116 | 116 | if (NULL !== $mInfo) { |
| 117 | 117 | $info[] = $mInfo; |
| 118 | 118 | } |
| 119 | - } catch (\Exception $e) { |
|
| 119 | + }catch (\Exception $e) { |
|
| 120 | 120 | Logger::getInstance()->errorLog($e->getMessage()); |
| 121 | 121 | } |
| 122 | 122 | } |
@@ -244,7 +244,7 @@ discard block |
||
| 244 | 244 | $payload = $this->extractModelFields($namespace); |
| 245 | 245 | $reflector = new \ReflectionClass($namespace); |
| 246 | 246 | $namespace = $reflector->getShortName(); |
| 247 | - } else { |
|
| 247 | + }else { |
|
| 248 | 248 | $namespace = $model; |
| 249 | 249 | } |
| 250 | 250 | |
@@ -331,10 +331,10 @@ discard block |
||
| 331 | 331 | "required" => $field->isNotNull(), |
| 332 | 332 | 'format' => $format, |
| 333 | 333 | ]; |
| 334 | - if(count($field->getValueSet())) { |
|
| 334 | + if (count($field->getValueSet())) { |
|
| 335 | 335 | $info['enum'] = array_values($field->getValueSet()); |
| 336 | 336 | } |
| 337 | - if(null !== $field->getDefaultValue()) { |
|
| 337 | + if (null !== $field->getDefaultValue()) { |
|
| 338 | 338 | $info['default'] = $field->getDefaultValue(); |
| 339 | 339 | } |
| 340 | 340 | $payload[$field->getPhpName()] = $info; |
@@ -342,7 +342,7 @@ discard block |
||
| 342 | 342 | } elseif (null !== $reflector && $reflector->isSubclassOf(self::DTO_INTERFACE)) { |
| 343 | 343 | $payload = $this->extractDtoProperties($namespace); |
| 344 | 344 | } |
| 345 | - } catch (\Exception $e) { |
|
| 345 | + }catch (\Exception $e) { |
|
| 346 | 346 | Logger::getInstance()->errorLog($e->getMessage()); |
| 347 | 347 | } |
| 348 | 348 | |
@@ -373,7 +373,7 @@ discard block |
||
| 373 | 373 | $return = $this->extractReturn($modelNamespace, $docComments); |
| 374 | 374 | $url = array_pop($route); |
| 375 | 375 | $methodInfo = [ |
| 376 | - 'url' => str_replace("/" . $module . "/api", '', $url), |
|
| 376 | + 'url' => str_replace("/".$module."/api", '', $url), |
|
| 377 | 377 | 'method' => $info['http'], |
| 378 | 378 | 'description' => $info['label'], |
| 379 | 379 | 'return' => $return, |
@@ -384,7 +384,7 @@ discard block |
||
| 384 | 384 | $this->setRequestParams($method, $methodInfo, $modelNamespace, $docComments); |
| 385 | 385 | $this->setQueryParams($method, $methodInfo); |
| 386 | 386 | $this->setRequestHeaders($reflection, $methodInfo); |
| 387 | - } catch (\Exception $e) { |
|
| 387 | + }catch (\Exception $e) { |
|
| 388 | 388 | Logger::getInstance()->errorLog($e->getMessage()); |
| 389 | 389 | } |
| 390 | 390 | } |
@@ -534,10 +534,10 @@ discard block |
||
| 534 | 534 | $formatted = [ |
| 535 | 535 | "swagger" => "2.0", |
| 536 | 536 | "host" => preg_replace('/^(http|https)\:\/\/(.*)\/$/i', '$2', Router::getInstance()->getRoute('', true)), |
| 537 | - "basePath" => '/' . $module['name'] . '/api', |
|
| 537 | + "basePath" => '/'.$module['name'].'/api', |
|
| 538 | 538 | "schemes" => [Request::getInstance()->getServer('HTTPS') == 'on' ? "https" : "http"], |
| 539 | 539 | "info" => [ |
| 540 | - "title" => _('Documentación API módulo ') . $module['name'], |
|
| 540 | + "title" => _('Documentación API módulo ').$module['name'], |
|
| 541 | 541 | "version" => Config::getParam('api.version', '1.0.0'), |
| 542 | 542 | "contact" => [ |
| 543 | 543 | "name" => Config::getParam("author", "Fran López"), |
@@ -550,7 +550,7 @@ discard block |
||
| 550 | 550 | foreach ($endpoints as $model) { |
| 551 | 551 | foreach ($model as $endpoint) { |
| 552 | 552 | if (!preg_match('/^\/(admin|api)\//i', $endpoint['url']) && strlen($endpoint['url'])) { |
| 553 | - $url = preg_replace('/\/' . $module['name'] . '\/api/i', '', $endpoint['url']); |
|
| 553 | + $url = preg_replace('/\/'.$module['name'].'\/api/i', '', $endpoint['url']); |
|
| 554 | 554 | $description = $endpoint['description']; |
| 555 | 555 | $method = strtolower($endpoint['method']); |
| 556 | 556 | $paths[$url][$method] = [ |
@@ -585,16 +585,16 @@ discard block |
||
| 585 | 585 | foreach ($endpoint['objects'] as $name => $object) { |
| 586 | 586 | if (class_exists($name)) { |
| 587 | 587 | $class = GeneratorHelper::extractClassFromNamespace($name); |
| 588 | - if(array_key_exists('data', $endpoint['return']) && count(array_keys($object)) === count(array_keys($endpoint['return']['data']))) { |
|
| 588 | + if (array_key_exists('data', $endpoint['return']) && count(array_keys($object)) === count(array_keys($endpoint['return']['data']))) { |
|
| 589 | 589 | $classDefinition = [ |
| 590 | 590 | 'type' => 'object', |
| 591 | - '$ref' => '#/definitions/' . $class, |
|
| 591 | + '$ref' => '#/definitions/'.$class, |
|
| 592 | 592 | ]; |
| 593 | - } else { |
|
| 593 | + }else { |
|
| 594 | 594 | $classDefinition = [ |
| 595 | 595 | 'type' => 'array', |
| 596 | 596 | 'items' => [ |
| 597 | - '$ref' => '#/definitions/' . $class, |
|
| 597 | + '$ref' => '#/definitions/'.$class, |
|
| 598 | 598 | ], |
| 599 | 599 | ]; |
| 600 | 600 | } |
@@ -612,7 +612,7 @@ discard block |
||
| 612 | 612 | 'required' => true, |
| 613 | 613 | 'schema' => [ |
| 614 | 614 | 'type' => 'object', |
| 615 | - '$ref' => '#/definitions/' . $endpoint['payload']['type'], |
|
| 615 | + '$ref' => '#/definitions/'.$endpoint['payload']['type'], |
|
| 616 | 616 | ], |
| 617 | 617 | ]; |
| 618 | 618 | } |
@@ -645,7 +645,7 @@ discard block |
||
| 645 | 645 | protected function extractDtoName($dto, $isArray = false) |
| 646 | 646 | { |
| 647 | 647 | $dto = explode('\\', $dto); |
| 648 | - $modelDto = array_pop($dto) . "Dto"; |
|
| 648 | + $modelDto = array_pop($dto)."Dto"; |
|
| 649 | 649 | if ($isArray) { |
| 650 | 650 | $modelDto .= "List"; |
| 651 | 651 | } |
@@ -695,10 +695,10 @@ discard block |
||
| 695 | 695 | { |
| 696 | 696 | |
| 697 | 697 | $methodInfo['headers'] = []; |
| 698 | - foreach($reflection->getProperties() as $property) { |
|
| 698 | + foreach ($reflection->getProperties() as $property) { |
|
| 699 | 699 | $doc = $property->getDocComment(); |
| 700 | 700 | preg_match('/@header\ (.*)\n/i', $doc, $headers); |
| 701 | - if(count($headers)) { |
|
| 701 | + if (count($headers)) { |
|
| 702 | 702 | $header = [ |
| 703 | 703 | "name" => $headers[1], |
| 704 | 704 | "in" => "header", |
@@ -710,13 +710,13 @@ discard block |
||
| 710 | 710 | |
| 711 | 711 | // Extract description |
| 712 | 712 | preg_match('/@label\ (.*)\n/i', $doc, $label); |
| 713 | - if(count($label)) { |
|
| 713 | + if (count($label)) { |
|
| 714 | 714 | $header['description'] = _($label[1]); |
| 715 | 715 | } |
| 716 | 716 | |
| 717 | 717 | // Extract default value |
| 718 | 718 | preg_match('/@default\ (.*)\n/i', $doc, $default); |
| 719 | - if(count($default)) { |
|
| 719 | + if (count($default)) { |
|
| 720 | 720 | $header['default'] = $default[1]; |
| 721 | 721 | } |
| 722 | 722 | $methodInfo['headers'][] = $header; |
@@ -746,7 +746,7 @@ discard block |
||
| 746 | 746 | foreach ($method->getParameters() as $parameter) { |
| 747 | 747 | $parameterName = $parameter->getName(); |
| 748 | 748 | $types = []; |
| 749 | - preg_match_all('/\@param\ (.*)\ \$' . $parameterName . '$/im', $docComments, $types); |
|
| 749 | + preg_match_all('/\@param\ (.*)\ \$'.$parameterName.'$/im', $docComments, $types); |
|
| 750 | 750 | if (count($types) > 1) { |
| 751 | 751 | $methodInfo['parameters'][$parameterName] = $types[1][0]; |
| 752 | 752 | } |