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::getParamInfo()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 22

Duplication

Lines 22
Ratio 100 %

Code Coverage

Tests 16
CRAP Score 4.0032

Importance

Changes 0
Metric Value
cc 4
nc 3
nop 1
dl 22
loc 22
ccs 16
cts 17
cp 0.9412
crap 4.0032
rs 9.568
c 0
b 0
f 0
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\Utils\AnnotationParams;
12
use PhpBoot\Utils\Logger;
13
use PhpBoot\Utils\TypeHint;
14
15
class ParamAnnotationHandler
16
{
17
18 3 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...
19
    {
20
21 3
        $paramType = null;
22 3
        $paramName = null;
23 3
        $paramDoc = '';
24 3
        if(substr($text, 0, 1) == '$'){ //带$前缀的是变量
25 3
            $params = new AnnotationParams($text, 2);
26 3
            $paramName = substr($params->getParam(0), 1);
27 3
            $paramDoc = $params->getRawParam(1, '');
28 3
        }else{
29 3
            $params = new AnnotationParams($text, 3);
30 3
            if ($params->count() >=2 && substr($params->getParam(1), 0, 1) == '$'){
31 3
                $paramType = $params->getParam(0); //TODO 检测类型是否合法
32 3
                $paramName = substr($params->getParam(1), 1);
33 3
                $paramDoc = $params->getRawParam(2, '');
34 3
            }else{
35
                \PhpBoot\abort(new AnnotationSyntaxException("@param $text syntax error"));
36
            }
37
        }
38 3
        return [$paramType, $paramName, $paramDoc];
39
    }
40
    /**
41
     * @param ControllerContainer $container
42
     * @param AnnotationBlock|AnnotationTag $ann
43
     * @param EntityContainerBuilder $entityBuilder
44
     */
45 3
    public function __invoke(ControllerContainer $container, $ann, EntityContainerBuilder $entityBuilder)
46
    {
47 3
        if(!$ann->parent){
48
            //Logger::debug("The annotation \"@{$ann->name} {$ann->description}\" of {$container->getClassName()} should be used with parent route");
49
            return;
50
        }
51 3
        $target = $ann->parent->name;
52 3
        $route = $container->getRoute($target);
53 3
        if(!$route){
54
            //Logger::debug("The annotation \"@{$ann->name} {$ann->description}\" of {$container->getClassName()}::$target should be used with parent route");
55
            return ;
56
        }
57 3
        $className = $container->getClassName();
58
59 3
        list($paramType, $paramName, $paramDoc) = self::getParamInfo($ann->description);
60
61 3
        $paramMeta = $route->getRequestHandler()->getParamMeta($paramName);
62 3
        $paramMeta or \PhpBoot\abort(new AnnotationSyntaxException("$className::$target param $paramName not exist "));
63
        //TODO 检测声明的类型和注释的类型是否匹配
64 3 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...
65 3
            $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 "));
66 3
            $container = ContainerFactory::create($entityBuilder, $paramMeta->type);
67 3
            $paramMeta->container = $container;
68 3
        }
69 3
        $paramMeta->description = $paramDoc;
70
71 3
        $responseHandler = $route->getResponseHandler();
72 3
        if($paramMeta->isPassedByReference && $responseHandler){
73 3
            $mappings = $responseHandler->getMappings();
74 3
            foreach ($mappings as $k => $v){
75 3
                if($v->source == 'params.'.$paramMeta->name){
76 3
                    $v->description = $paramMeta->description;
77 3
                    $v->type = $paramMeta->type;
78 3
                    $v->container = $paramMeta->container;
79 3
                }
80 3
            }
81 3
        }
82
83
    }
84
}