1 | <?php |
||
15 | final class AnnotationDriver implements ModelConfigurationDriverInterface |
||
16 | { |
||
17 | /** |
||
18 | * @var Reader |
||
19 | */ |
||
20 | private $reader; |
||
21 | |||
22 | /** |
||
23 | * @var string |
||
24 | */ |
||
25 | private $userClass; |
||
26 | |||
27 | /** |
||
28 | * Constructor. |
||
29 | * |
||
30 | * @param Reader $annotationReader |
||
31 | * @param string $userClass |
||
32 | */ |
||
33 | 10 | public function __construct(Reader $annotationReader, $userClass) |
|
38 | |||
39 | /** |
||
40 | * {@inheritdoc} |
||
41 | * |
||
42 | * @throws \LogicException If one of the annotations is missing |
||
43 | * @throws \LogicException If one property has multiple "auth" annotations |
||
44 | */ |
||
45 | 10 | public function getMetadataForUser() |
|
46 | { |
||
47 | 10 | $reflection = new ReflectionClass($this->userClass); |
|
48 | 10 | $properties = $reflection->getProperties(); |
|
49 | 10 | $loginProperty = $passwordProperty = $apiKeyProperty = $lastActionProperty = null; |
|
50 | |||
51 | 10 | foreach ($properties as $reflectionProperty) { |
|
52 | 10 | foreach (array('login', 'password', 'apiKey', 'lastAction') as $annotation) { |
|
53 | 10 | $class = sprintf('Ma27\\ApiKeyAuthenticationBundle\\Annotation\\%s', ucfirst($annotation)); |
|
54 | 10 | $annotationObject = $this->reader->getPropertyAnnotation($reflectionProperty, $class); |
|
|
|||
55 | |||
56 | 10 | if ($annotationObject) { |
|
57 | switch ($annotation) { |
||
58 | 10 | case 'login': |
|
59 | 9 | if (!empty($loginProperty)) { |
|
60 | throw $this->createDuplicateAnnotationException(); |
||
61 | } |
||
62 | |||
63 | 9 | $loginProperty = $reflectionProperty; |
|
64 | 9 | break; |
|
65 | 10 | case 'password': |
|
66 | 9 | if (!empty($passwordProperty)) { |
|
67 | throw $this->createDuplicateAnnotationException(); |
||
68 | } |
||
69 | |||
70 | 9 | $passwordProperty = $reflectionProperty; |
|
71 | 9 | break; |
|
72 | 10 | case 'apiKey': |
|
73 | 10 | if (!empty($apiKeyProperty)) { |
|
74 | throw $this->createDuplicateAnnotationException(); |
||
75 | } |
||
76 | |||
77 | 10 | $apiKeyProperty = $reflectionProperty; |
|
78 | 10 | break; |
|
79 | 9 | case 'lastAction': |
|
80 | 9 | if (!empty($lastActionProperty)) { |
|
81 | throw $this->createDuplicateAnnotationException(); |
||
82 | } |
||
83 | |||
84 | 9 | $lastActionProperty = $reflectionProperty; |
|
85 | 9 | } |
|
86 | |||
87 | if ($loginProperty |
||
88 | 10 | && $passwordProperty |
|
89 | 10 | && $apiKeyProperty |
|
90 | 10 | && $lastActionProperty |
|
91 | 10 | ) { |
|
92 | 9 | break; |
|
93 | } |
||
94 | |||
95 | 10 | continue; |
|
96 | } |
||
97 | 10 | } |
|
98 | 10 | } |
|
99 | |||
100 | 10 | if (!$loginProperty || !$passwordProperty || !$apiKeyProperty) { |
|
101 | 1 | throw new \LogicException(sprintf( |
|
102 | 1 | 'A user class must have a "%s", "%s", "%s" annotation!', |
|
103 | 1 | 'Login', |
|
104 | 1 | 'Password', |
|
105 | 'ApiKey' |
||
106 | 1 | )); |
|
107 | } |
||
108 | |||
109 | 9 | return new ClassMetadata( |
|
110 | 9 | $reflection, |
|
111 | 9 | $this->userClass, |
|
112 | array( |
||
113 | 9 | ClassMetadata::LOGIN_PROPERTY => $loginProperty, |
|
114 | 9 | ClassMetadata::PASSWORD_PROPERTY => $passwordProperty, |
|
115 | 9 | ClassMetadata::API_KEY_PROPERTY => $apiKeyProperty, |
|
116 | 9 | ClassMetadata::LAST_ACTION_PROPERTY => $lastActionProperty, |
|
117 | ) |
||
118 | 9 | ); |
|
119 | } |
||
120 | |||
121 | /** |
||
122 | * Creates the exception when. |
||
123 | * |
||
124 | * @return \InvalidArgumentException |
||
125 | */ |
||
126 | private function createDuplicateAnnotationException() |
||
130 | } |
||
131 |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
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.