GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

BindAnnotationHandler::__invoke()   B
last analyzed

Complexity

Conditions 10
Paths 14

Size

Total Lines 49

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 29
CRAP Score 11.3278

Importance

Changes 0
Metric Value
cc 10
nc 14
nop 3
dl 0
loc 49
ccs 29
cts 38
cp 0.7632
crap 11.3278
rs 7.246
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace PhpBoot\Controller\Annotations;
4
5
use PhpBoot\Annotation\AnnotationBlock;
6
use PhpBoot\Annotation\AnnotationTag;
7
use PhpBoot\Controller\ControllerContainer;
8
use PhpBoot\Entity\ContainerFactory;
9
use PhpBoot\Entity\EntityContainerBuilder;
10
use PhpBoot\Exceptions\AnnotationSyntaxException;
11
use PhpBoot\Metas\ReturnMeta;
12
use PhpBoot\Utils\AnnotationParams;
13
use PhpBoot\Utils\Logger;
14
15
class BindAnnotationHandler
16
{
17
    /**
18
     * @param ControllerContainer $container
19
     * @param AnnotationBlock|AnnotationTag $ann
20
     * @param EntityContainerBuilder $entityBuilder
21
     */
22 3
    public function __invoke(ControllerContainer $container, $ann, EntityContainerBuilder $entityBuilder)
23
    {
24 3
        if(!$ann->parent || !$ann->parent->parent){
25
            Logger::debug("The annotation \"@{$ann->name} {$ann->description}\" of {$container->getClassName()} should be used with parent param/return");
26
            return;
27
        }
28 3
        $target = $ann->parent->parent->name;
29 3
        $route = $container->getRoute($target);
30 3
        if(!$route){
31
            Logger::debug("The annotation \"@{$ann->name} {$ann->description}\" of {$container->getClassName()}::$target should be used with parent param/return");
32
            return ;
33
        }
34
35 3
        $params = new AnnotationParams($ann->description, 2);
36
37 3
        $params->count()>0 or \PhpBoot\abort(new AnnotationSyntaxException("The annotation \"@{$ann->name} {$ann->description}\" of {$container->getClassName()}::$target require 1 param, {$params->count()} given"));
38
39 3
        $handler = $route->getResponseHandler();
40
41 3
        if ($ann->parent->name == 'return'){
42
            list($target, $return) = $handler->getMappingBySource('return');
43
            if($return){
44
                $handler->eraseMapping($target);
45
                $handler->setMapping($params[0], $return);
46
            }
47
48 3
        }elseif($ann->parent->name == 'param'){
49 3
            list($paramType, $paramName, $paramDoc) = ParamAnnotationHandler::getParamInfo($ann->parent->description);
0 ignored issues
show
Unused Code introduced by
The assignment to $paramType is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
50
51 3
            $paramMeta = $route->getRequestHandler()->getParamMeta($paramName);
52 3
            if($paramMeta->isPassedByReference){
53 3
                list($target, $ori) = $handler->getMappingBySource('params.'.$paramName);
54 3
                if($ori){
55 3
                    $handler->eraseMapping($target);
56 3
                }
57
                //输出绑定
58 3
                $handler->setMapping(
59 3
                    $params[0],
60 3
                    new ReturnMeta(
61 3
                        'params.'.$paramMeta->name,
62 3
                        $paramMeta->type, $paramDoc,
63 3
                        ContainerFactory::create($entityBuilder, $paramMeta->type)
64 3
                    )
65 3
                );
66 3
            }else{
67 3
                $paramMeta->source = $params[0];
68
            }
69 3
        }
70
    }
71
}