Completed
Push — master ( daf0f3...03b505 )
by Fran
09:59
created

Api::createApiDocs()   C

Complexity

Conditions 7
Paths 6

Size

Total Lines 29
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 56

Importance

Changes 4
Bugs 0 Features 0
Metric Value
cc 7
eloc 20
nc 6
nop 1
dl 0
loc 29
rs 6.7272
c 4
b 0
f 0
ccs 0
cts 23
cp 0
crap 56
1
<?php
2
    namespace PSFS\controller;
3
4
    use PSFS\base\types\Controller;
5
    use PSFS\services\DocumentorService;
6
7
    /**
8
     * Class Api
9
     * @package PSFS\controller
10
     */
11
    class Api extends Controller
12
    {
13
        const DOMAIN = 'ROOT';
14
        const PSFS_DOC = 'psfs';
15
        const SWAGGER_DOC = 'swagger';
16
        const POSTMAN_DOC = 'postman';
17
        const HTML_DOC = 'html';
18
19
        /**
20
         * @Inyectable
21
         * @var \PSFS\services\DocumentorService $srv
22
         */
23
        protected $srv;
24
25
        /**
26
         * @GET
27
         * @route /api/__doc/{type}
28
         *
29
         * @param string $type
30
         *
31
         * @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...
32
         */
33
        public function createApiDocs($type = Api::PSFS_DOC)
34
        {
35
            ini_set('memory_limit', -1);
36
            ini_set('max_execution_time', -1);
37
38
            $endpoints = [];
39
            $modules = $this->srv->getModules();
40
41
            switch (strtolower($type)) {
42
                case self::SWAGGER_DOC:
43
                    $doc = DocumentorService::swaggerFormatter($modules);
44
                    break;
45
                default:
46
                case self::HTML_DOC:
1 ignored issue
show
Unused Code introduced by
case self::HTML_DOC: does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
47
                case self::PSFS_DOC:
48
                    if (count($modules)) {
49
                        foreach ($modules as $module) {
50
                            $endpoints = array_merge($endpoints, $this->srv->extractApiEndpoints($module));
51
                        }
52
                    }
53
                    $doc = $endpoints;
54
                    break;
55
            }
56
57
            ini_restore('max_execution_time');
58
            ini_restore('memory_limit');
59
60
            return ($type === self::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 145 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...
61
        }
62
    }