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   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 70
Duplicated Lines 38.57 %

Coupling/Cohesion

Components 0
Dependencies 10

Test Coverage

Coverage 93.48%

Importance

Changes 0
Metric Value
dl 27
loc 70
ccs 43
cts 46
cp 0.9348
rs 10
c 0
b 0
f 0
wmc 13
lcom 0
cbo 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getParamInfo() 22 22 4
B __invoke() 5 39 9

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
}