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.

ValidateAnnotationHandler::__invoke()   B
last analyzed

Complexity

Conditions 9
Paths 12

Size

Total Lines 37

Duplication

Lines 37
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 90

Importance

Changes 0
Metric Value
cc 9
nc 12
nop 2
dl 37
loc 37
ccs 0
cts 33
cp 0
crap 90
rs 7.7724
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\Exceptions\AnnotationSyntaxException;
9
use PhpBoot\Utils\AnnotationParams;
10
use PhpBoot\Utils\Logger;
11
use PhpBoot\Validator\Validator;
12
13 View Code Duplication
class ValidateAnnotationHandler
0 ignored issues
show
Duplication introduced by
This class 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...
14
{
15
    /**
16
     * @param ConsoleContainer $container
17
     * @param AnnotationBlock|AnnotationTag $ann
18
     */
19
    public function __invoke(ConsoleContainer $container, $ann)
20
    {
21
        if(!$ann->parent || !$ann->parent->parent){
22
            Logger::debug("The annotation \"@{$ann->name} {$ann->description}\" of {$container->getClassName()} should be used with parent parent");
23
            return;
24
        }
25
        $target = $ann->parent->parent->name;
26
        $command = $container->getCommand($target);
27
        if(!$command){
28
            Logger::debug("The annotation \"@{$ann->name} {$ann->description}\" of {$container->getClassName()}::$target should be used with parent parent");
29
            return ;
30
        }
31
        $params = new AnnotationParams($ann->description, 2);
32
33
        count($params)>0 or \PhpBoot\abort(new AnnotationSyntaxException("The annotation \"@{$ann->name} {$ann->description}\" of {$container->getClassName()}::$target require 1 param, {$params->count()} given"));
34
35
        if($ann->parent->name == 'param'){
36
            list($paramType, $paramName, $paramDoc) = ParamAnnotationHandler::getParamInfo($ann->parent->description);
0 ignored issues
show
Unused Code introduced by
The assignment to $paramType is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
Unused Code introduced by
The assignment to $paramDoc is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
37
38
            $paramMeta = $command->getParamMeta($paramName);
39
            if($params->count()>1){
40
                $paramMeta->validation = [$params[0], $params[1]];
41
            }else{
42
                $paramMeta->validation = $params[0];
43
                if($paramMeta->validation) {
44
                    $v = new Validator();
45
                    $v->rule($paramMeta->validation, $paramMeta->name);
46
                    if ($v->hasRule('optional', $paramMeta->name)) {
47
                        $paramMeta->isOptional = true;
48
                    }
49
                }
50
            }
51
52
            return;
53
        }
54
        Logger::debug("The annotation \"@{$ann->name} {$ann->description}\" of {$container->getClassName()}::$target should be used with parent parent");
55
    }
56
}