Passed
Push — master ( 77d814...60093d )
by Fran
03:40
created
src/services/DocumentorService.php 1 patch
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -42,10 +42,10 @@  discard block
 block discarded – undo
42 42
                     if (!preg_match('/^ROOT/i', $module) && $module == $requestModule) {
43 43
                         $modules = [
44 44
                             'name' => $module,
45
-                            'path' => realpath($info['template'] . DIRECTORY_SEPARATOR . '..'),
45
+                            'path' => realpath($info['template'].DIRECTORY_SEPARATOR.'..'),
46 46
                         ];
47 47
                     }
48
-                } catch (\Exception $e) {
48
+                }catch (\Exception $e) {
49 49
                     $modules[] = $e->getMessage();
50 50
                 }
51 51
             }
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
      */
64 64
     public function extractApiEndpoints(array $module)
65 65
     {
66
-        $module_path = $module['path'] . DIRECTORY_SEPARATOR . 'Api';
66
+        $module_path = $module['path'].DIRECTORY_SEPARATOR.'Api';
67 67
         $module_name = $module['name'];
68 68
         $endpoints = [];
69 69
         if (file_exists($module_path)) {
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
             if (count($finder)) {
73 73
                 /** @var \SplFileInfo $file */
74 74
                 foreach ($finder as $file) {
75
-                    $namespace = "\\{$module_name}\\Api\\" . str_replace('.php', '', $file->getFilename());
75
+                    $namespace = "\\{$module_name}\\Api\\".str_replace('.php', '', $file->getFilename());
76 76
                     $info = $this->extractApiInfo($namespace, $module_name);
77 77
                     if (!empty($info)) {
78 78
                         $endpoints[$namespace] = $info;
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
                     if (NULL !== $mInfo) {
102 102
                         $info[] = $mInfo;
103 103
                     }
104
-                } catch (\Exception $e) {
104
+                }catch (\Exception $e) {
105 105
                     Logger::getInstance()->errorLog($e->getMessage());
106 106
                 }
107 107
             }
@@ -313,7 +313,7 @@  discard block
 block discarded – undo
313 313
             } elseif (null !== $reflector && $reflector->isSubclassOf(self::DTO_INTERFACE)) {
314 314
                 $payload = $this->extractDtoProperties($namespace);
315 315
             }
316
-        } catch (\Exception $e) {
316
+        }catch (\Exception $e) {
317 317
             Logger::getInstance()->errorLog($e->getMessage());
318 318
         }
319 319
 
@@ -352,18 +352,18 @@  discard block
 block discarded – undo
352 352
                     unset($methodInfo['return']['objects']);
353 353
                     if (in_array($methodInfo['method'], ['POST', 'PUT'])) {
354 354
                         $methodInfo['payload'] = $this->extractPayload($modelNamespace, $docComments);
355
-                    } elseif($method->getNumberOfParameters() > 0) {
355
+                    } elseif ($method->getNumberOfParameters() > 0) {
356 356
                         $methodInfo['parameters'] = [];
357
-                        foreach($method->getParameters() as $parameter) {
357
+                        foreach ($method->getParameters() as $parameter) {
358 358
                             $parameterName = $parameter->getName();
359 359
                             $types = [];
360 360
                             preg_match_all('/\@param\ (.*)\ \$'.$parameterName.'$/im', $docComments, $types);
361
-                            if(count($types) > 1) {
361
+                            if (count($types) > 1) {
362 362
                                 $methodInfo['parameters'][$parameterName] = $types[1][0];
363 363
                             }
364 364
                         }
365 365
                     }
366
-                } catch (\Exception $e) {
366
+                }catch (\Exception $e) {
367 367
                     jpre($e->getMessage());
368 368
                     Logger::getInstance()->errorLog($e->getMessage());
369 369
                 }
@@ -445,13 +445,13 @@  discard block
 block discarded – undo
445 445
                 ]]);
446 446
                 if (array_key_exists($subDtoName, $subDto)) {
447 447
                     $definitions = $subDto;
448
-                } else {
448
+                }else {
449 449
                     $definitions[$subDtoName] = $subDto;
450 450
                 }
451 451
                 $definition[$name]['properties'][$field] = [
452
-                    '$ref' => "#/definitions/" . $subDtoName,
452
+                    '$ref' => "#/definitions/".$subDtoName,
453 453
                 ];
454
-            } else {
454
+            }else {
455 455
                 list($type, $format) = self::translateSwaggerFormats($format);
456 456
                 $dto['properties'][$field] = [
457 457
                     "type" => $type,
@@ -473,8 +473,8 @@  discard block
 block discarded – undo
473 473
     private static function swaggerResponses() {
474 474
         $codes = [200, 400, 404, 500];
475 475
         $responses = [];
476
-        foreach($codes as $code) {
477
-            switch($code) {
476
+        foreach ($codes as $code) {
477
+            switch ($code) {
478 478
                 default:
479 479
                 case 200:
480 480
                     $message = _('Successful response');
@@ -526,10 +526,10 @@  discard block
 block discarded – undo
526 526
         $formatted = [
527 527
             "swagger" => "2.0",
528 528
             "host" => preg_replace('/^(http|https)\:\/\/(.*)\/$/i', '$2', Router::getInstance()->getRoute('', true)),
529
-            "basePath" => '/' . $module['name'] . '/api',
529
+            "basePath" => '/'.$module['name'].'/api',
530 530
             "schemes" => [Request::getInstance()->getServer('https') == 'on' ? "https" : "http"],
531 531
             "info" => [
532
-                "title" => _('Documentación API módulo ') . $module['name'],
532
+                "title" => _('Documentación API módulo ').$module['name'],
533 533
                 "version" => Config::getParam('api.version', '1.0'),
534 534
                 "contact" => [
535 535
                     "name" => Config::getParam("author", "Fran López"),
@@ -541,7 +541,7 @@  discard block
 block discarded – undo
541 541
         $endpoints = DocumentorService::getInstance()->extractApiEndpoints($module);
542 542
         foreach ($endpoints as $model) {
543 543
             foreach ($model as $endpoint) {
544
-                if(!preg_match('/^\/admin\//i', $endpoint['url']) && strlen($endpoint['url'])) {
544
+                if (!preg_match('/^\/admin\//i', $endpoint['url']) && strlen($endpoint['url'])) {
545 545
                     $url = preg_replace('/\/'.$module['name'].'\/api/i', '', $endpoint['url']);
546 546
                     $description = $endpoint['description'];
547 547
                     $method = strtolower($endpoint['method']);
@@ -552,8 +552,8 @@  discard block
 block discarded – undo
552 552
                         'responses' => self::swaggerResponses(),
553 553
                         'parameters' => [],
554 554
                     ];
555
-                    if(array_key_exists('parameters', $endpoint)) {
556
-                        foreach($endpoint['parameters'] as $parameter => $type) {
555
+                    if (array_key_exists('parameters', $endpoint)) {
556
+                        foreach ($endpoint['parameters'] as $parameter => $type) {
557 557
                             list($type, $format) = self::translateSwaggerFormats($type);
558 558
                             $paths[$url][$method]['parameters'][] = [
559 559
                                 'in' => 'path',
@@ -565,19 +565,19 @@  discard block
 block discarded – undo
565 565
                         }
566 566
 
567 567
                     }
568
-                    foreach($endpoint['objects'] as $name => $object) {
569
-                        if(class_exists($name)) {
568
+                    foreach ($endpoint['objects'] as $name => $object) {
569
+                        if (class_exists($name)) {
570 570
                             $class = GeneratorHelper::extractClassFromNamespace($name);
571 571
                             $classDefinition = [
572 572
                                 'type' => 'object',
573
-                                '$ref' => '#/definitions/' . $class,
573
+                                '$ref' => '#/definitions/'.$class,
574 574
                             ];
575 575
                             $paths[$url][$method]['responses'][200]['schema']['properties']['data'] = $classDefinition;
576 576
                             $dtos += self::extractSwaggerDefinition($class, $object);
577
-                            if(!isset($paths[$url][$method]['tags']) || !in_array($class, $paths[$url][$method]['tags'])) {
577
+                            if (!isset($paths[$url][$method]['tags']) || !in_array($class, $paths[$url][$method]['tags'])) {
578 578
                                 $paths[$url][$method]['tags'][] = $class;
579 579
                             }
580
-                            if(array_key_exists('payload', $endpoint)) {
580
+                            if (array_key_exists('payload', $endpoint)) {
581 581
                                 $paths[$url][$method]['parameters'][] = [
582 582
                                     'in' => 'body',
583 583
                                     'name' => $class,
@@ -605,7 +605,7 @@  discard block
 block discarded – undo
605 605
     protected function extractDtoName($dto, $isArray = false)
606 606
     {
607 607
         $dto = explode('\\', $dto);
608
-        $modelDto = array_pop($dto) . "Dto";
608
+        $modelDto = array_pop($dto)."Dto";
609 609
         if ($isArray) {
610 610
             $modelDto .= "List";
611 611
         }
Please login to merge, or discard this patch.