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.
Passed
Push — master ( abbaf5...bc538d )
by cao
03:04
created

BindAnnotationHandler::__invoke()   C

Complexity

Conditions 10
Paths 14

Size

Total Lines 49
Code Lines 32

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 34
CRAP Score 10.1167

Importance

Changes 0
Metric Value
cc 10
eloc 32
nc 14
nop 3
dl 0
loc 49
ccs 34
cts 38
cp 0.8947
crap 10.1167
rs 5.5471
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"));
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as or instead of || is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
38
39 3
        $handler = $route->getResponseHandler();
40
41 3
        if ($ann->parent->name == 'return'){
42 1
            list($target, $return) = $handler->getMappingBySource('return');
43 1
            if($return){
44 1
                $handler->eraseMapping($target);
45 1
                $handler->setMapping($params[0], $return);
46 1
            }
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
}