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 ( 11f67e...911369 )
by Robert
02:03
created

AnnotationReader   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 97.14%

Importance

Changes 0
Metric Value
wmc 13
lcom 1
cbo 4
dl 0
loc 86
ccs 34
cts 35
cp 0.9714
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A isApi() 0 4 1
A getDescription() 0 4 1
A getName() 0 4 1
A getParameters() 0 17 3
A getApi() 0 7 1
A getMethod() 0 10 2
A parseParameterDocblock() 0 10 3
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
7
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
8
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
9
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
10
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
11
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
12
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
13
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
14
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
15
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
16
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
17
 *
18
 * This software consists of voluntary contributions made by many individuals
19
 * and is licensed under the MIT license. For more information, see
20
 * <https://github.com/digitalkaoz/php-ipfs>
21
 */
22
23
namespace IPFS\Utils;
24
25
use Doctrine\Common\Annotations\AnnotationReader as BaseReader;
26
use IPFS\Annotation\Api;
27
use IPFS\Annotation\Param;
28
use phpDocumentor\Reflection\DocBlockFactory;
29
30
class AnnotationReader
31
{
32
    /**
33
     * @var BaseReader
34
     */
35
    private $reader;
36
    /**
37
     * @var DocBlockFactory
38
     */
39
    private $docBlockFactory;
40
41 6
    public function __construct(BaseReader $reader, DocBlockFactory $docBlockFactory)
42
    {
43 6
        $this->reader = $reader;
44 6
        $this->docBlockFactory = $docBlockFactory;
45 6
    }
46
47 2
    public function isApi($method): bool
48
    {
49 2
        return (bool) $this->getApi($method);
50
    }
51
52 1
    public function getDescription($method): string
53
    {
54 1
        return $this->docBlockFactory->create($this->getMethod($method))->getSummary();
55
    }
56
57 1
    public function getName($method): string
58
    {
59 1
        return (string) $this->getApi($method)->name;
60
    }
61
62
    /**
63
     * @return array|Param[]
64
     */
65 1
    public function getParameters($method): array
66
    {
67 1
        $reflection = $this->getMethod($method);
68 1
        $parameters = [];
69 1
        $docBlock = $this->docBlockFactory->create($reflection->getDocComment());
70 1
        $params = $docBlock->getTagsByName('param');
71
72 1
        foreach ($reflection->getParameters() as $parameter) {
73 1
            $parameters[$parameter->name] = new Param(
74 1
                $parameter->name,
75 1
                $this->parseParameterDocblock($params, $parameter),
76 1
                $parameter->isDefaultValueAvailable() ? $parameter->getDefaultValue() : Param::class
77
            );
78
        }
79
80 1
        return $parameters;
81
    }
82
83
    /**
84
     * @return Api|null
85
     */
86 3
    private function getApi($method)
87
    {
88 3
        return $this->reader->getMethodAnnotation(
89 3
            $this->getMethod($method),
90 3
            Api::class
91
        );
92
    }
93
94 5
    private function getMethod($method): \ReflectionMethod
95
    {
96 5
        if ($method instanceof \ReflectionMethod) {
97 1
            return $method;
98
        }
99
100 4
        list($api, $method) = explode('::', $method);
101
102 4
        return new \ReflectionMethod($api, $method);
103
    }
104
105 1
    private function parseParameterDocblock(array $params, \ReflectionParameter $parameter): string
106
    {
107 1
        foreach ($params as $param) {
108 1
            if ($parameter->name === $param->getVariableName()) {
109 1
                return $param->getDescription()->render();
110
            }
111
        }
112
113
        return '';
114
    }
115
}
116