Passed
Push — master ( f6e68e...a7b3d9 )
by Fran
03:43
created

DocumentorController::createApiDocs()   C

Complexity

Conditions 7
Paths 10

Size

Total Lines 29
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 56

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 7
eloc 21
nc 10
nop 1
dl 0
loc 29
ccs 0
cts 22
cp 0
crap 56
rs 6.7272
c 1
b 0
f 0
1
<?php
2
namespace PSFS\controller;
3
4
use PSFS\base\Router;
5
use PSFS\base\types\Controller;
6
use PSFS\services\DocumentorService;
7
8
class DocumentorController extends Controller {
9
    const DOMAIN = 'ROOT';
10
11
    /**
12
     * @Inyectable
13
     * @var \PSFS\services\DocumentorService $srv
14
     */
15
    protected $srv;
16
17
    /**
18
     * @GET
19
     * @CACHE 600
20
     * @label Generador de documentación API
21
     * @route /{domain}/api/doc
22
     *
23
     * @param string $domain
24
     *
25
     * @return string JSON
0 ignored issues
show
Documentation introduced by
Should the return type not be string|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
26
     */
27
    public function createApiDocs($domain)
28
    {
29
        ini_set('memory_limit', -1);
30
        ini_set('max_execution_time', -1);
31
32
        $type = $this->getRequest()->get('type') ?: ApiController::PSFS_DOC;
33
34
        $endpoints = [];
35
        $module = $this->srv->getModules($domain);
36
        if(empty($module)) {
37
            return Router::getInstance()->httpNotFound(null, true);
38
        }
39
        switch (strtolower($type)) {
40
            case ApiController::SWAGGER_DOC:
41
                $doc = DocumentorService::swaggerFormatter($module);
42
                break;
43
            default:
44
            case ApiController::HTML_DOC:
45
            case ApiController::PSFS_DOC:
46
                $endpoints = array_merge($endpoints, $this->srv->extractApiEndpoints($module));
47
                $doc = $endpoints;
48
                break;
49
        }
50
51
        ini_restore('max_execution_time');
52
        ini_restore('memory_limit');
53
54
        return ($type === ApiController::HTML_DOC) ? $this->render('documentation.html.twig', ["data" => json_encode($doc)]) : $this->json($doc, 200);
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 150 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
55
    }
56
}