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.
Completed
Push — master ( 0268aa...3ec9bd )
by cao
05:24
created

ParamAnnotationHandler::__invoke()   B

Complexity

Conditions 5
Paths 6

Size

Total Lines 26
Code Lines 16

Duplication

Lines 5
Ratio 19.23 %

Code Coverage

Tests 16
CRAP Score 5.0342

Importance

Changes 0
Metric Value
cc 5
eloc 16
nc 6
nop 3
dl 5
loc 26
ccs 16
cts 18
cp 0.8889
crap 5.0342
rs 8.439
c 0
b 0
f 0
1
<?php
2
3
namespace PhpBoot\Console\Annotations;
4
5
use PhpBoot\Annotation\AnnotationBlock;
6
use PhpBoot\Annotation\AnnotationTag;
7
use PhpBoot\Console\ConsoleContainer;
8
use PhpBoot\Controller\ControllerContainer;
9
use PhpBoot\Entity\ContainerFactory;
10
use PhpBoot\Entity\EntityContainerBuilder;
11
use PhpBoot\Exceptions\AnnotationSyntaxException;
12
use PhpBoot\Utils\AnnotationParams;
13
use PhpBoot\Utils\Logger;
14
use PhpBoot\Utils\TypeHint;
15
16
class ParamAnnotationHandler
17
{
18
19 1 View Code Duplication
    static public function getParamInfo($text)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
20
    {
21
22 1
        $paramType = null;
23 1
        $paramName = null;
24 1
        $paramDoc = '';
25 1
        if(substr($text, 0, 1) == '$'){ //带$前缀的是变量
26
            $params = new AnnotationParams($text, 2);
27
            $paramName = substr($params->getParam(0), 1);
28
            $paramDoc = $params->getRawParam(1, '');
29
        }else{
30 1
            $params = new AnnotationParams($text, 3);
31 1
            if ($params->count() >=2 && substr($params->getParam(1), 0, 1) == '$'){
32 1
                $paramType = $params->getParam(0); //TODO 检测类型是否合法
33 1
                $paramName = substr($params->getParam(1), 1);
34 1
                $paramDoc = $params->getRawParam(2, '');
35 1
            }else{
36
                \PhpBoot\abort(new AnnotationSyntaxException("@param $text syntax error"));
37
            }
38
        }
39 1
        return [$paramType, $paramName, $paramDoc];
40
    }
41
    /**
42
     * @param ConsoleContainer $container
43
     * @param AnnotationBlock|AnnotationTag $ann
44
     * @param EntityContainerBuilder $entityBuilder
45
     */
46 1
    public function __invoke(ConsoleContainer $container, $ann, EntityContainerBuilder $entityBuilder)
47
    {
48 1
        if(!$ann->parent){
49
            //Logger::debug("The annotation \"@{$ann->name} {$ann->description}\" of {$container->getClassName()} should be used with parent route");
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
50
            return;
51
        }
52 1
        $target = $ann->parent->name;
53 1
        $command = $container->getCommand($target);
54 1
        if(!$command){
55
            //Logger::debug("The annotation \"@{$ann->name} {$ann->description}\" of {$container->getClassName()}::$target should be used with parent route");
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
56
            return ;
57
        }
58 1
        $className = $container->getClassName();
59
60 1
        list($paramType, $paramName, $paramDoc) = self::getParamInfo($ann->description);
61
62 1
        $paramMeta = $command->getParamMeta($paramName);
63 1
        $paramMeta or \PhpBoot\abort(new AnnotationSyntaxException("$className::$target param $paramName not exist "));
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...
64
        //TODO 检测声明的类型和注释的类型是否匹配
65 1 View Code Duplication
        if($paramType){
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
66 1
            $paramMeta->type = TypeHint::normalize($paramType, $className);//or \PhpBoot\abort(new AnnotationSyntaxException("{$container->getClassName()}::{$ann->parent->name} @{$ann->name} syntax error, param $paramName unknown type:$paramType "));
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
67 1
            $container = ContainerFactory::create($entityBuilder, $paramMeta->type);
68 1
            $paramMeta->container = $container;
69 1
        }
70 1
        $paramMeta->description = $paramDoc;
71
    }
72
}