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 ( 6daa1e...29b462 )
by Maximilian
03:41
created

AnnotationDriver::getMetadataForUser()   C

Complexity

Conditions 19
Paths 30

Size

Total Lines 75
Code Lines 49

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 42
CRAP Score 20.9849

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 75
ccs 42
cts 51
cp 0.8235
rs 5.2752
cc 19
eloc 49
nc 30
nop 0
crap 20.9849

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Ma27\ApiKeyAuthenticationBundle\Annotation\Driver;
4
5
use Doctrine\Common\Annotations\Reader;
6
use Ma27\ApiKeyAuthenticationBundle\Model\User\ClassMetadata;
7
use Ma27\ApiKeyAuthenticationBundle\Model\User\ModelConfigurationDriverInterface;
8
use ReflectionClass;
9
10
/**
11
 * Annotation driver which parses the annotations of the user model instance.
12
 */
13
final class AnnotationDriver implements ModelConfigurationDriverInterface
14
{
15
    /**
16
     * @var Reader
17
     */
18
    private $reader;
19
20
    /**
21
     * @var string
22
     */
23
    private $userClass;
24
25
    /**
26
     * Constructor.
27
     *
28
     * @param Reader $annotationReader
29
     * @param string $userClass
30
     */
31 7
    public function __construct(Reader $annotationReader, $userClass)
32
    {
33 7
        $this->reader = $annotationReader;
34 7
        $this->userClass = (string) $userClass;
35 7
    }
36
37
    /**
38
     * {@inheritdoc}
39
     *
40
     * @throws \LogicException If one of the annotations is missing
41
     * @throws \LogicException If one property has multiple "auth" annotations
42
     */
43 7
    public function getMetadataForUser()
44
    {
45 7
        $reflection = new ReflectionClass($this->userClass);
46 7
        $properties = $reflection->getProperties();
47 7
        $loginProperty = $passwordProperty = $apiKeyProperty = $lastActionProperty = null;
48
49 7
        foreach ($properties as $reflectionProperty) {
50 7
            foreach (array('login', 'password', 'apiKey', 'lastAction') as $annotation) {
51 7
                $class = sprintf('Ma27\\ApiKeyAuthenticationBundle\\Annotation\\%s', ucfirst($annotation));
52 7
                $annotationObject = $this->reader->getPropertyAnnotation($reflectionProperty, $class);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $annotationObject is correct as $this->reader->getProper...ectionProperty, $class) (which targets Doctrine\Common\Annotati...getPropertyAnnotation()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
53
54 7
                if ($annotationObject) {
55
                    switch ($annotation) {
56 7
                        case 'login':
57 6
                            if (!empty($loginProperty)) {
58
                                throw $this->createDuplicateAnnotationException();
59
                            }
60
61 6
                            $loginProperty = $reflectionProperty;
62 6
                            break;
63 7
                        case 'password':
64 6
                            if (!empty($passwordProperty)) {
65
                                throw $this->createDuplicateAnnotationException();
66
                            }
67
68 6
                            $passwordProperty = $reflectionProperty;
69 6
                            break;
70 7
                        case 'apiKey':
71 7
                            if (!empty($apiKeyProperty)) {
72
                                throw $this->createDuplicateAnnotationException();
73
                            }
74
75 7
                            $apiKeyProperty = $reflectionProperty;
76 7
                            break;
77
                        case 'lastAction':
78
                            if (!empty($lastActionProperty)) {
79
                                throw $this->createDuplicateAnnotationException();
80
                            }
81
82
                            $lastActionProperty = $reflectionProperty;
83
                    }
84
85
                    if ($loginProperty
86 7
                        && $passwordProperty
87 7
                        && $apiKeyProperty
88 7
                        && $lastActionProperty
89 7
                    ) {
90
                        break;
91
                    }
92
93 7
                    continue;
94
                }
95 7
            }
96 7
        }
97
98 7
        if (!$loginProperty || !$passwordProperty || !$apiKeyProperty) {
99 1
            throw new \LogicException(sprintf(
100 1
                'A user class must have a "%s", "%s", "%s" annotation!',
101 1
                'Login',
102 1
                'Password',
103
                'ApiKey'
104 1
            ));
105
        }
106
107 6
        return new ClassMetadata(
108 6
            $reflection,
109 6
            $this->userClass,
110
            array(
0 ignored issues
show
Documentation introduced by
array(\Ma27\ApiKeyAuthen...=> $lastActionProperty) is of type array<string|integer,obj...flectionProperty>|null>, but the function expects a array<integer,object<ReflectionProperty>>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
111 6
                ClassMetadata::LOGIN_PROPERTY       => $loginProperty,
112 6
                ClassMetadata::PASSWORD_PROPERTY    => $passwordProperty,
113 6
                ClassMetadata::API_KEY_PROPERTY     => $apiKeyProperty,
114 6
                ClassMetadata::LAST_ACTION_PROPERTY => $lastActionProperty,
115
            )
116 6
        );
117
    }
118
119
    /**
120
     * Creates the exception when.
121
     *
122
     * @return \InvalidArgumentException
123
     */
124
    private function createDuplicateAnnotationException()
125
    {
126
        return new \InvalidArgumentException('None of the Ma27\\ApiKeyAuthenticationBundle annotations can be declared twice!');
127
    }
128
}
129