Completed
Push — master ( e4227f...5cbf20 )
by Fran
03:34
created

Api::createApiDocs()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 23
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 4
eloc 16
c 3
b 0
f 0
nc 4
nop 1
dl 0
loc 23
ccs 0
cts 19
cp 0
crap 20
rs 8.7972
1
<?php
2
    namespace PSFS\controller;
3
4
    use PSFS\base\types\Controller;
5
6
    /**
7
     * Class Api
8
     * @package PSFS\controller
9
     */
10
    class Api extends Controller
11
    {
12
        const DOMAIN = 'ROOT';
13
        const PSFS_DOC = 'psfs';
14
        const SWAGGER_DOC = 'swagger';
15
        const POSTMAN_DOC = 'postman';
16
17
        /**
18
         * @Inyectable
19
         * @var \PSFS\services\DocumentorService $srv
20
         */
21
        protected $srv;
22
23
        /**
24
         * @GET
25
         * @route /api/__doc/{type}
26
         *
27
         * @param string $type
28
         *
29
         * @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...
30
         */
31
        public function createApiDocs($type = 'psfs')
32
        {
33
            $doc = $endpoints = [];
0 ignored issues
show
Unused Code introduced by
$doc is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
34
            $modules = $this->srv->getModules();
35
            ini_set('memory_limit', -1);
36
            ini_set('max_execution_time', -1);
37
            if (count($modules)) {
38
                foreach ($modules as $module) {
39
                    $endpoints = array_merge($endpoints, $this->srv->extractApiEndpoints($module));
40
                }
41
            }
42
            ini_restore('max_execution_time');
43
            ini_restore('memory_limit');
44
45
            switch (strtolower($type)) {
46
                default:
47
                case self::PSFS_DOC:
48
                    $doc = $endpoints;
49
                    break;
50
            }
51
52
            return $this->json($doc, 200);
53
        }
54
    }