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.

ParamAnnotationHandler::__invoke()   A
last analyzed

Complexity

Conditions 5
Paths 6

Size

Total Lines 26

Duplication

Lines 5
Ratio 19.23 %

Code Coverage

Tests 16
CRAP Score 5.0342

Importance

Changes 0
Metric Value
cc 5
nc 6
nop 3
dl 5
loc 26
ccs 16
cts 18
cp 0.8889
crap 5.0342
rs 9.1928
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...
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");
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");
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 "));
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 "));
67 1
            $container = ContainerFactory::create($entityBuilder, $paramMeta->type);
68 1
            $paramMeta->container = $container;
69 1
        }
70 1
        $paramMeta->description = $paramDoc;
71
    }
72
}