Passed
Push — master ( 77c76c...926ba1 )
by Fran
03:51
created
src/services/DocumentorService.php 1 patch
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -52,10 +52,10 @@  discard block
 block discarded – undo
52 52
                     if (!preg_match('/^ROOT/i', $module) && $module == $requestModule) {
53 53
                         $modules = [
54 54
                             'name' => $module,
55
-                            'path' => realpath($info['template'] . DIRECTORY_SEPARATOR . '..'),
55
+                            'path' => realpath($info['template'].DIRECTORY_SEPARATOR.'..'),
56 56
                         ];
57 57
                     }
58
-                } catch (\Exception $e) {
58
+                }catch (\Exception $e) {
59 59
                     $modules[] = $e->getMessage();
60 60
                 }
61 61
             }
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
      */
74 74
     public function extractApiEndpoints(array $module)
75 75
     {
76
-        $module_path = $module['path'] . DIRECTORY_SEPARATOR . 'Api';
76
+        $module_path = $module['path'].DIRECTORY_SEPARATOR.'Api';
77 77
         $module_name = $module['name'];
78 78
         $endpoints = [];
79 79
         if (file_exists($module_path)) {
@@ -82,8 +82,8 @@  discard block
 block discarded – undo
82 82
             if (count($finder)) {
83 83
                 /** @var \SplFileInfo $file */
84 84
                 foreach ($finder as $file) {
85
-                    if(preg_match('/User\.php$/i', $file->getFilename())) {
86
-                        $namespace = "\\{$module_name}\\Api\\" . str_replace('.php', '', $file->getFilename());
85
+                    if (preg_match('/User\.php$/i', $file->getFilename())) {
86
+                        $namespace = "\\{$module_name}\\Api\\".str_replace('.php', '', $file->getFilename());
87 87
                         $info = $this->extractApiInfo($namespace, $module_name);
88 88
                         if (!empty($info)) {
89 89
                             $endpoints[$namespace] = $info;
@@ -109,13 +109,13 @@  discard block
 block discarded – undo
109 109
             $reflection = new \ReflectionClass($namespace);
110 110
             foreach ($reflection->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) {
111 111
                 try {
112
-                    if($method->getShortName() === 'checkLogin') {
112
+                    if ($method->getShortName() === 'checkLogin') {
113 113
                         $mInfo = $this->extractMethodInfo($namespace, $method, $reflection, $module);
114 114
                         if (NULL !== $mInfo) {
115 115
                             $info[] = $mInfo;
116 116
                         }
117 117
                     }
118
-                } catch (\Exception $e) {
118
+                }catch (\Exception $e) {
119 119
                     Logger::getInstance()->errorLog($e->getMessage());
120 120
                 }
121 121
             }
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
             $payload = $this->extractModelFields($namespace);
243 243
             $reflector = new \ReflectionClass($namespace);
244 244
             $namespace = $reflector->getShortName();
245
-        } else {
245
+        }else {
246 246
             $namespace = $model;
247 247
         }
248 248
 
@@ -332,7 +332,7 @@  discard block
 block discarded – undo
332 332
             } elseif (null !== $reflector && $reflector->isSubclassOf(self::DTO_INTERFACE)) {
333 333
                 $payload = $this->extractDtoProperties($namespace);
334 334
             }
335
-        } catch (\Exception $e) {
335
+        }catch (\Exception $e) {
336 336
             Logger::getInstance()->errorLog($e->getMessage());
337 337
         }
338 338
 
@@ -363,7 +363,7 @@  discard block
 block discarded – undo
363 363
                     $return = $this->extractReturn($modelNamespace, $docComments);
364 364
                     $url = array_pop($route);
365 365
                     $methodInfo = [
366
-                        'url' => str_replace("/" . $module . "/api", '', $url),
366
+                        'url' => str_replace("/".$module."/api", '', $url),
367 367
                         'method' => $info['http'],
368 368
                         'description' => $info['label'],
369 369
                         'return' => $return,
@@ -374,7 +374,7 @@  discard block
 block discarded – undo
374 374
                     $this->setRequestParams($method, $methodInfo, $modelNamespace, $docComments);
375 375
                     $this->setQueryParams($method, $methodInfo);
376 376
                     $this->setRequestHeaders($reflection, $methodInfo);
377
-                } catch (\Exception $e) {
377
+                }catch (\Exception $e) {
378 378
                     jpre($e->getMessage());
379 379
                     Logger::getInstance()->errorLog($e->getMessage());
380 380
                 }
@@ -524,10 +524,10 @@  discard block
 block discarded – undo
524 524
         $formatted = [
525 525
             "swagger" => "2.0",
526 526
             "host" => preg_replace('/^(http|https)\:\/\/(.*)\/$/i', '$2', Router::getInstance()->getRoute('', true)),
527
-            "basePath" => '/' . $module['name'] . '/api',
527
+            "basePath" => '/'.$module['name'].'/api',
528 528
             "schemes" => [Request::getInstance()->getServer('HTTPS') == 'on' ? "https" : "http"],
529 529
             "info" => [
530
-                "title" => _('Documentación API módulo ') . $module['name'],
530
+                "title" => _('Documentación API módulo ').$module['name'],
531 531
                 "version" => Config::getParam('api.version', '1.0'),
532 532
                 "contact" => [
533 533
                     "name" => Config::getParam("author", "Fran López"),
@@ -540,7 +540,7 @@  discard block
 block discarded – undo
540 540
         foreach ($endpoints as $model) {
541 541
             foreach ($model as $endpoint) {
542 542
                 if (!preg_match('/^\/(admin|api)\//i', $endpoint['url']) && strlen($endpoint['url'])) {
543
-                    $url = preg_replace('/\/' . $module['name'] . '\/api/i', '', $endpoint['url']);
543
+                    $url = preg_replace('/\/'.$module['name'].'\/api/i', '', $endpoint['url']);
544 544
                     $description = $endpoint['description'];
545 545
                     $method = strtolower($endpoint['method']);
546 546
                     $paths[$url][$method] = [
@@ -575,16 +575,16 @@  discard block
 block discarded – undo
575 575
                     foreach ($endpoint['objects'] as $name => $object) {
576 576
                         if (class_exists($name)) {
577 577
                             $class = GeneratorHelper::extractClassFromNamespace($name);
578
-                            if(array_key_exists('data', $endpoint['return']) && count(array_keys($object)) === count(array_keys($endpoint['return']['data']))) {
578
+                            if (array_key_exists('data', $endpoint['return']) && count(array_keys($object)) === count(array_keys($endpoint['return']['data']))) {
579 579
                                 $classDefinition = [
580 580
                                     'type' => 'object',
581
-                                    '$ref' => '#/definitions/' . $class,
581
+                                    '$ref' => '#/definitions/'.$class,
582 582
                                 ];
583
-                            } else {
583
+                            }else {
584 584
                                 $classDefinition = [
585 585
                                     'type' => 'array',
586 586
                                     'items' => [
587
-                                        '$ref' => '#/definitions/' . $class,
587
+                                        '$ref' => '#/definitions/'.$class,
588 588
                                     ],
589 589
                                 ];
590 590
                             }
@@ -602,7 +602,7 @@  discard block
 block discarded – undo
602 602
                                     'required' => true,
603 603
                                     'schema' => [
604 604
                                         'type' => 'object',
605
-                                        '$ref' => '#/definitions/' . $endpoint['payload']['type'],
605
+                                        '$ref' => '#/definitions/'.$endpoint['payload']['type'],
606 606
                                     ],
607 607
                                 ];
608 608
                             }
@@ -629,7 +629,7 @@  discard block
 block discarded – undo
629 629
     protected function extractDtoName($dto, $isArray = false)
630 630
     {
631 631
         $dto = explode('\\', $dto);
632
-        $modelDto = array_pop($dto) . "Dto";
632
+        $modelDto = array_pop($dto)."Dto";
633 633
         if ($isArray) {
634 634
             $modelDto .= "List";
635 635
         }
@@ -679,10 +679,10 @@  discard block
 block discarded – undo
679 679
     {
680 680
 
681 681
         $methodInfo['headers'] = [];
682
-        foreach($reflection->getProperties() as $property) {
682
+        foreach ($reflection->getProperties() as $property) {
683 683
             $doc = $property->getDocComment();
684 684
             preg_match('/@header\ (.*)\n/i', $doc, $headers);
685
-            if(count($headers)) {
685
+            if (count($headers)) {
686 686
                 $header = [
687 687
                     "name" => $headers[1],
688 688
                     "in" => "header",
@@ -694,13 +694,13 @@  discard block
 block discarded – undo
694 694
 
695 695
                 // Extract description
696 696
                 preg_match('/@label\ (.*)\n/i', $doc, $label);
697
-                if(count($label)) {
697
+                if (count($label)) {
698 698
                     $header['description'] = _($label[1]);
699 699
                 }
700 700
 
701 701
                 // Extract default value
702 702
                 preg_match('/@default\ (.*)\n/i', $doc, $default);
703
-                if(count($default)) {
703
+                if (count($default)) {
704 704
                     $header['default'] = $default[1];
705 705
                 }
706 706
                 $methodInfo['headers'][] = $header;
@@ -730,7 +730,7 @@  discard block
 block discarded – undo
730 730
             foreach ($method->getParameters() as $parameter) {
731 731
                 $parameterName = $parameter->getName();
732 732
                 $types = [];
733
-                preg_match_all('/\@param\ (.*)\ \$' . $parameterName . '$/im', $docComments, $types);
733
+                preg_match_all('/\@param\ (.*)\ \$'.$parameterName.'$/im', $docComments, $types);
734 734
                 if (count($types) > 1) {
735 735
                     $methodInfo['parameters'][$parameterName] = $types[1][0];
736 736
                 }
Please login to merge, or discard this patch.