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.
Completed
Push — master ( 0268aa...3ec9bd )
by cao
05:24
created

ValidateAnnotationHandler::__invoke()   D

Complexity

Conditions 9
Paths 12

Size

Total Lines 37
Code Lines 25

Duplication

Lines 37
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 90

Importance

Changes 0
Metric Value
cc 9
eloc 25
nc 12
nop 2
dl 37
loc 37
ccs 0
cts 33
cp 0
crap 90
rs 4.909
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"));
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as or instead of || is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
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
}