Passed
Push — master ( a7b3d9...78560e )
by Fran
03:42
created
src/controller/DocumentorController.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
         $download = $this->getRequest()->get('download') ?: false;
34 34
 
35 35
         $module = $this->srv->getModules($domain);
36
-        if(empty($module)) {
36
+        if (empty($module)) {
37 37
             return Router::getInstance()->httpNotFound(null, true);
38 38
         }
39 39
         switch (strtolower($type)) {
@@ -53,11 +53,11 @@  discard block
 block discarded – undo
53 53
         ini_restore('max_execution_time');
54 54
         ini_restore('memory_limit');
55 55
 
56
-        if($download && $type === ApiController::SWAGGER_DOC) {
56
+        if ($download && $type === ApiController::SWAGGER_DOC) {
57 57
             return $this->download(\GuzzleHttp\json_encode($doc), 'application/json', 'swagger.json');
58
-        } elseif($type === ApiController::HTML_DOC) {
58
+        } elseif ($type === ApiController::HTML_DOC) {
59 59
             return $this->render('documentation.html.twig', ["data" => json_encode($doc)]);
60
-        } else {
60
+        }else {
61 61
             return $this->json($doc, 200);
62 62
         }
63 63
     }
Please login to merge, or discard this patch.
src/services/DocumentorService.php 1 patch
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -41,10 +41,10 @@  discard block
 block discarded – undo
41 41
                     if (!preg_match('/^ROOT/i', $module) && $module == $requestModule) {
42 42
                         $modules = [
43 43
                             'name' => $module,
44
-                            'path' => realpath($info['template'] . DIRECTORY_SEPARATOR . '..'),
44
+                            'path' => realpath($info['template'].DIRECTORY_SEPARATOR.'..'),
45 45
                         ];
46 46
                     }
47
-                } catch (\Exception $e) {
47
+                }catch (\Exception $e) {
48 48
                     $modules[] = $e->getMessage();
49 49
                 }
50 50
             }
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
      */
63 63
     public function extractApiEndpoints(array $module)
64 64
     {
65
-        $module_path = $module['path'] . DIRECTORY_SEPARATOR . 'Api';
65
+        $module_path = $module['path'].DIRECTORY_SEPARATOR.'Api';
66 66
         $module_name = $module['name'];
67 67
         $endpoints = [];
68 68
         if (file_exists($module_path)) {
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
             if (count($finder)) {
72 72
                 /** @var \SplFileInfo $file */
73 73
                 foreach ($finder as $file) {
74
-                    $namespace = "\\{$module_name}\\Api\\" . str_replace('.php', '', $file->getFilename());
74
+                    $namespace = "\\{$module_name}\\Api\\".str_replace('.php', '', $file->getFilename());
75 75
                     $info = $this->extractApiInfo($namespace, $module_name);
76 76
                     if (!empty($info)) {
77 77
                         $endpoints[$namespace] = $info;
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
                     if (NULL !== $mInfo) {
101 101
                         $info[] = $mInfo;
102 102
                     }
103
-                } catch (\Exception $e) {
103
+                }catch (\Exception $e) {
104 104
                     Logger::getInstance()->errorLog($e->getMessage());
105 105
                 }
106 106
             }
@@ -312,7 +312,7 @@  discard block
 block discarded – undo
312 312
             } elseif (null !== $reflector && $reflector->isSubclassOf(self::DTO_INTERFACE)) {
313 313
                 $payload = $this->extractDtoProperties($namespace);
314 314
             }
315
-        } catch (\Exception $e) {
315
+        }catch (\Exception $e) {
316 316
             Logger::getInstance()->errorLog($e->getMessage());
317 317
         }
318 318
 
@@ -351,18 +351,18 @@  discard block
 block discarded – undo
351 351
                     unset($methodInfo['return']['objects']);
352 352
                     if (in_array($methodInfo['method'], ['POST', 'PUT'])) {
353 353
                         $methodInfo['payload'] = $this->extractPayload($modelNamespace, $docComments);
354
-                    } elseif($method->getNumberOfParameters() > 0) {
354
+                    } elseif ($method->getNumberOfParameters() > 0) {
355 355
                         $methodInfo['parameters'] = [];
356
-                        foreach($method->getParameters() as $parameter) {
356
+                        foreach ($method->getParameters() as $parameter) {
357 357
                             $parameterName = $parameter->getName();
358 358
                             $types = [];
359 359
                             preg_match_all('/\@param\ (.*)\ \$'.$parameterName.'$/im', $docComments, $types);
360
-                            if(count($types) > 1) {
360
+                            if (count($types) > 1) {
361 361
                                 $methodInfo['parameters'][$parameterName] = $types[1][0];
362 362
                             }
363 363
                         }
364 364
                     }
365
-                } catch (\Exception $e) {
365
+                }catch (\Exception $e) {
366 366
                     jpre($e->getMessage());
367 367
                     Logger::getInstance()->errorLog($e->getMessage());
368 368
                 }
@@ -444,13 +444,13 @@  discard block
 block discarded – undo
444 444
                 ]]);
445 445
                 if (array_key_exists($subDtoName, $subDto)) {
446 446
                     $definitions = $subDto;
447
-                } else {
447
+                }else {
448 448
                     $definitions[$subDtoName] = $subDto;
449 449
                 }
450 450
                 $definition[$name]['properties'][$field] = [
451
-                    '$ref' => "#/definitions/" . $subDtoName,
451
+                    '$ref' => "#/definitions/".$subDtoName,
452 452
                 ];
453
-            } else {
453
+            }else {
454 454
                 list($type, $format) = self::translateSwaggerFormats($format);
455 455
                 $dto['properties'][$field] = [
456 456
                     "type" => $type,
@@ -472,8 +472,8 @@  discard block
 block discarded – undo
472 472
     private static function swaggerResponses() {
473 473
         $codes = [200, 400, 404, 500];
474 474
         $responses = [];
475
-        foreach($codes as $code) {
476
-            switch($code) {
475
+        foreach ($codes as $code) {
476
+            switch ($code) {
477 477
                 default:
478 478
                 case 200:
479 479
                     $message = _('Successful response');
@@ -524,10 +524,10 @@  discard block
 block discarded – undo
524 524
     {
525 525
         $formatted = [
526 526
             "swagger" => "2.0",
527
-            "host" => preg_replace('/^(http|https)\:\/\//i', '', Router::getInstance()->getRoute('', true)) . $module['name'] . '/api',
527
+            "host" => preg_replace('/^(http|https)\:\/\//i', '', Router::getInstance()->getRoute('', true)).$module['name'].'/api',
528 528
             "schemes" => ["http", "https"],
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"),
@@ -539,7 +539,7 @@  discard block
 block discarded – undo
539 539
         $endpoints = DocumentorService::getInstance()->extractApiEndpoints($module);
540 540
         foreach ($endpoints as $model) {
541 541
             foreach ($model as $endpoint) {
542
-                if(!preg_match('/^\/admin\//i', $endpoint['url']) && strlen($endpoint['url'])) {
542
+                if (!preg_match('/^\/admin\//i', $endpoint['url']) && strlen($endpoint['url'])) {
543 543
                     $url = preg_replace('/\/'.$module['name'].'\/api/i', '', $endpoint['url']);
544 544
                     $description = $endpoint['description'];
545 545
                     $method = strtolower($endpoint['method']);
@@ -550,8 +550,8 @@  discard block
 block discarded – undo
550 550
                         'responses' => self::swaggerResponses(),
551 551
                         'parameters' => [],
552 552
                     ];
553
-                    if(array_key_exists('parameters', $endpoint)) {
554
-                        foreach($endpoint['parameters'] as $parameter => $type) {
553
+                    if (array_key_exists('parameters', $endpoint)) {
554
+                        foreach ($endpoint['parameters'] as $parameter => $type) {
555 555
                             list($type, $format) = self::translateSwaggerFormats($type);
556 556
                             $paths[$url][$method]['parameters'][] = [
557 557
                                 'in' => 'path',
@@ -563,19 +563,19 @@  discard block
 block discarded – undo
563 563
                         }
564 564
 
565 565
                     }
566
-                    foreach($endpoint['objects'] as $name => $object) {
567
-                        if(class_exists($name)) {
566
+                    foreach ($endpoint['objects'] as $name => $object) {
567
+                        if (class_exists($name)) {
568 568
                             $class = GeneratorHelper::extractClassFromNamespace($name);
569 569
                             $classDefinition = [
570 570
                                 'type' => 'object',
571
-                                '$ref' => '#/definitions/' . $class,
571
+                                '$ref' => '#/definitions/'.$class,
572 572
                             ];
573 573
                             $paths[$url][$method]['responses'][200]['schema']['properties']['data'] = $classDefinition;
574 574
                             $dtos += self::extractSwaggerDefinition($class, $object);
575
-                            if(!isset($paths[$url][$method]['tags']) || !in_array($class, $paths[$url][$method]['tags'])) {
575
+                            if (!isset($paths[$url][$method]['tags']) || !in_array($class, $paths[$url][$method]['tags'])) {
576 576
                                 $paths[$url][$method]['tags'][] = $class;
577 577
                             }
578
-                            if(array_key_exists('payload', $endpoint)) {
578
+                            if (array_key_exists('payload', $endpoint)) {
579 579
                                 $paths[$url][$method]['parameters'][] = [
580 580
                                     'in' => 'body',
581 581
                                     'name' => $class,
@@ -603,7 +603,7 @@  discard block
 block discarded – undo
603 603
     protected function extractDtoName($dto, $isArray = false)
604 604
     {
605 605
         $dto = explode('\\', $dto);
606
-        $modelDto = array_pop($dto) . "Dto";
606
+        $modelDto = array_pop($dto)."Dto";
607 607
         if ($isArray) {
608 608
             $modelDto .= "List";
609 609
         }
Please login to merge, or discard this patch.