These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace DoctrineModule\Authentication\Storage; |
||
6 | |||
7 | use DoctrineModule\Options\Authentication as AuthenticationOptions; |
||
8 | use Laminas\Authentication\Storage\StorageInterface; |
||
9 | |||
10 | /** |
||
11 | * This class implements StorageInterface and allow to save the result of an authentication against an object repository |
||
12 | * |
||
13 | * @link http://www.doctrine-project.org/ |
||
14 | */ |
||
15 | class ObjectRepository implements StorageInterface |
||
16 | { |
||
17 | /** @var AuthenticationOptions */ |
||
18 | protected $options; |
||
19 | |||
20 | /** |
||
21 | * @param mixed[]|AuthenticationOptions $options |
||
22 | */ |
||
23 | 4 | public function setOptions($options) : ObjectRepository |
|
24 | { |
||
25 | 4 | if (! $options instanceof AuthenticationOptions) { |
|
26 | 1 | $options = new AuthenticationOptions($options); |
|
27 | } |
||
28 | |||
29 | 4 | $this->options = $options; |
|
30 | |||
31 | 4 | return $this; |
|
32 | } |
||
33 | |||
34 | /** |
||
35 | * Constructor |
||
36 | * |
||
37 | * @param mixed[]|AuthenticationOptions $options |
||
38 | */ |
||
39 | 4 | public function __construct($options = []) |
|
40 | { |
||
41 | 4 | $this->setOptions($options); |
|
42 | 4 | } |
|
43 | |||
44 | 1 | public function isEmpty() : bool |
|
45 | { |
||
46 | 1 | return $this->options->getStorage()->isEmpty(); |
|
47 | } |
||
48 | |||
49 | /** |
||
50 | * This function assumes that the storage only contains identifier values (which is the case if |
||
51 | * the ObjectRepository authentication adapter is used). |
||
52 | */ |
||
53 | 1 | public function read() : ?object |
|
54 | { |
||
55 | 1 | $identity = $this->options->getStorage()->read(); |
|
56 | 1 | if ($identity) { |
|
57 | 1 | return $this->options->getObjectRepository()->find($identity); |
|
58 | } |
||
59 | |||
60 | return null; |
||
61 | } |
||
62 | |||
63 | /** |
||
64 | * Will return the key of the identity. If only the key is needed, this avoids an |
||
65 | * unnecessary db call |
||
66 | * |
||
67 | * @return mixed |
||
68 | */ |
||
69 | 1 | public function readKeyOnly() |
|
70 | { |
||
71 | 1 | return $identity = $this->options->getStorage()->read(); |
|
0 ignored issues
–
show
|
|||
72 | } |
||
73 | |||
74 | /** |
||
75 | * @param mixed $identity |
||
76 | */ |
||
77 | 1 | public function write($identity) : void |
|
78 | { |
||
79 | 1 | $metadataInfo = $this->options->getClassMetadata(); |
|
80 | 1 | $identifierValues = $metadataInfo->getIdentifierValues($identity); |
|
81 | |||
82 | 1 | $this->options->getStorage()->write($identifierValues); |
|
83 | 1 | } |
|
84 | |||
85 | public function clear() : void |
||
86 | { |
||
87 | $this->options->getStorage()->clear(); |
||
88 | } |
||
89 | } |
||
90 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.