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.
Test Failed
Push — master ( 0b829b...741320 )
by cao
02:34
created

AnnotationEnabledTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 10
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
wmc 1
lcom 0
cbo 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A testMethod() 0 4 1
1
<?php
2
3
namespace PhpBoot\Annotation;
4
use Doctrine\Common\Cache\ApcCache;
5
use Doctrine\Common\Cache\Cache;
6
use PhpBoot\Cache\CheckableCache;
7
use PhpBoot\Cache\ClassModifiedChecker;
8
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
9
use phpDocumentor\Reflection\DocBlock\StandardTagFactory;
10
use phpDocumentor\Reflection\DocBlock\Tag;
11
use phpDocumentor\Reflection\DocBlock\Tags\Formatter;
12
use phpDocumentor\Reflection\DocBlockFactory;
13
use phpDocumentor\Reflection\FqsenResolver;
14
use phpDocumentor\Reflection\TypeResolver;
15
16
/**
17
 * AnnotationEnabledTest
18
 */
19
class AnnotationEnabledTest
20
{
21
    /**
22
     * testMethod
23
     */
24
    public function testMethod()
25
    {
26 4
27
    }
28 4
}
29 4
30
class AnnotationTagsOutput implements Formatter
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
31
{
32
    /**
33
     * Formats a tag into a string representation according to a specific format, such as Markdown.
34
     *
35 17
     * @param Tag $tag
36 17
     *
37 17
     * @return string
38 17
     */
39 17
    public function format(Tag $tag)
40 17
    {
41 17
        $this->tags[] = $tag;
42 17
        return strval($tag);
43
    }
44
    public $tags = [];
45
}
46
class AnnotationReader implements \ArrayAccess
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
47
{
48
    static public function createDocBlockFactory(){
0 ignored issues
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
49
        $fqsenResolver = new FqsenResolver();
50
        $tagFactory = new StandardTagFactory($fqsenResolver,[]);
51
        $descriptionFactory = new DescriptionFactory($tagFactory);
52 17
        $tagFactory->addService($descriptionFactory);
53
        $tagFactory->addService(new TypeResolver($fqsenResolver));
54 17
        $docBlockFactory = new DocBlockFactory($descriptionFactory, $tagFactory);
55 17
        return $docBlockFactory;
56 17
    }
57 17
58 17
    static public function assertAnnotationEnabled()
0 ignored issues
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
59 17
    {
60 17
        $rfl = new \ReflectionClass(AnnotationEnabledTest::class);
61
        !empty($rfl->getDocComment()) or \PhpBoot\abort('Annotation dose not work! If opcache is enable, please set opcache.save_comments=1 and opcache.load_comments=1');
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...
62 17
    }
63 17
    /**
64 17
     * load from class with local cache
65
     * TODO 增加 filter 能力
66
     * @param string $className
67
     * @param Cache $localCache
68
     * @return object
69
     */
70
    static public function read($className, Cache $localCache = null)
0 ignored issues
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
71
    {
72
        self::assertAnnotationEnabled();
73
        $rfl = new \ReflectionClass($className) or \PhpBoot\abort("load class $className failed");
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...
74
        $fileName = $rfl->getFileName();
75
        $key = str_replace('\\','.',self::class).md5($fileName.$className);
76
        $oldData = null;
77
        $cache = new CheckableCache($localCache?:new ApcCache());
0 ignored issues
show
Deprecated Code introduced by
The class Doctrine\Common\Cache\ApcCache has been deprecated with message: since version 1.6, use ApcuCache instead

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
78
        $res = $cache->get('ann:'.$key, null, $oldData, false);
79 17
        if($res === null){
80
            try{
81 17
                $meta = self::readWithoutCache($className);
82
                $cache->set($key, $meta, 0, $fileName?new ClassModifiedChecker($className):null);
83 17
                return $meta;
84 17
            }catch (\Exception $e){
85 17
                $cache->set($key, $e->getMessage(), 0, $fileName?new ClassModifiedChecker($className):null);
86
                throw $e;
87
            }
88 17
        }elseif(is_string($res)){
89 13
            \PhpBoot\abort($res);
90 13
        }else{
91 13
            return $res;
92 17
        }
93
    }
94 17
    /**
95 16
     * @param $className
96 12
     * @return self
97
     */
98 16
    static function readWithoutCache($className)
99 16
    {
100 16
        $reader = new self();
101 17
102 17
        $rfl = new \ReflectionClass($className);
103
        $reader->class = self::readAnnotationBlock($rfl->getDocComment());
104
        $reader->class->name = $className;
105
106
        //method annotations
107
        foreach ($rfl->getMethods() as $i){
108
            $block = self::readAnnotationBlock($i->getDocComment());
109
            $block->name = $i->getName();
0 ignored issues
show
Bug introduced by
Consider using $i->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
110
            $reader->methods[$i->getName()]=$block;
0 ignored issues
show
Bug introduced by
Consider using $i->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
111
        }
112 17
        //property annotations
113 View Code Duplication
        foreach ($rfl->getProperties() as $i){
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...
114
            if ($i->isStatic()) {
115 17
                continue;
116
            }
117 17
            $block = self::readAnnotationBlock($i->getDocComment());
118 17
            $block->name = $i->getName();
119 16
            $reader->properties[$i->getName()]=$block;
120
        }
121 17
        while ($rfl = $rfl->getParentClass()) {
122 17 View Code Duplication
            foreach ($rfl->getProperties(\ReflectionProperty::IS_PRIVATE) as $i) {
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...
123 17
                if ($i->isStatic()) {
124 17
                    continue;
125 17
                }
126 17
                $block = self::readAnnotationBlock($i->getDocComment());
127 17
                $block->name = $i->getName();
128 17
                $reader->properties[$i->getName()]=$block;
129 17
            }
130 17
        }
131 17
        return $reader;
132 17
    }
133 17
134 17
    static private function readAnnotationBlock($doc)
0 ignored issues
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
135 17
    {
136 17
        $annBlock = new AnnotationBlock();
137 17
        if(empty($doc)){
138 4
            return $annBlock;
139 4
        }
140 4
        $docFactory = AnnotationReader::createDocBlockFactory();
141 4
        $docBlock = $docFactory->create($doc);
142 4
        $annBlock->summary = $docBlock->getSummary();
143 17
        $annBlock->description = strval($docBlock->getDescription());
144 17
        $annBlock->children = [];
145 17
        $tags = $docBlock->getTags();
146 17
        foreach ($tags as $tag) {
147 17
            $annTag = new AnnotationTag();
148
            $desc = $tag->getDescription();
149
            $annTag->parent = $annBlock;
150
            $annTag->description = strval($desc);
151
            $annTag->name = $tag->getName();
152
            $annTag->children=[];
153
            if($desc){
154
                $output = new AnnotationTagsOutput();
155
                $desc->render($output);
156
                foreach ($output->tags as $child) {
157
                    $childTag = new AnnotationTag();
158
                    $childTag->parent = $annTag;
0 ignored issues
show
Documentation Bug introduced by
It seems like $annTag of type object<PhpBoot\Annotation\AnnotationTag> is incompatible with the declared type object<PhpBoot\Annotation\AnnotationBlock>|null of property $parent.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
159
                    $childTag->name = $child->getName();
160
                    $childTag->description = strval($child->getDescription());
161
                    $annTag->children[] = $childTag;
162
                }
163
            }
164 17
            $annBlock->children[] = $annTag;
165
        }
166 17
        return $annBlock;
167
    }
168
169 17
    /**
170
     * @var AnnotationBlock
171 17
     */
172
    public $class;
173
    /**
174
     * @var AnnotationBlock[]
175
     */
176
177
    public $methods=[];
178
    /**
179
     * @var AnnotationBlock[]
180
     */
181
    public $properties=[];
182
183
    public function offsetExists($offset)
184
    {
185
        return isset($this->$offset);
186
    }
187
188
    public function offsetGet($offset)
189
    {
190
        return $this->$offset;
191
    }
192
193
    public function offsetSet($offset, $value)
194
    {
195
        $this->$offset = $value;
196
    }
197
198
    public function offsetUnset($offset)
199
    {
200
        unset($this->$offset);
201
    }
202
}