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 9

Size/Duplication

Total Lines 57
Duplicated Lines 47.37 %

Coupling/Cohesion

Components 0
Dependencies 7

Test Coverage

Coverage 80%

Importance

Changes 0
Metric Value
dl 27
loc 57
ccs 28
cts 35
cp 0.8
rs 10
c 0
b 0
f 0
wmc 9
lcom 0
cbo 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getParamInfo() 22 22 4
A __invoke() 5 26 5

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\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
}