These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * Library for confirmation tokens. |
||
4 | * |
||
5 | * @link https://github.com/hiqdev/php-confirmator |
||
6 | * @package php-confirmator |
||
7 | * @license BSD-3-Clause |
||
8 | * @copyright Copyright (c) 2016-2017, HiQDev (http://hiqdev.com/) |
||
9 | */ |
||
10 | |||
11 | namespace hiqdev\php\confirmator; |
||
12 | |||
13 | trait ServiceTrait |
||
14 | { |
||
15 | /** |
||
16 | * @param array $data |
||
17 | * @return Token |
||
18 | */ |
||
19 | 3 | public function issueToken(array $data) |
|
20 | { |
||
21 | 3 | $token = new Token($this, $data); |
|
22 | 3 | $this->writeToken($token); |
|
23 | |||
24 | 3 | return $token; |
|
25 | } |
||
26 | |||
27 | 1 | public function checkToken($token, array $data) |
|
28 | { |
||
29 | 1 | $token = $this->findToken($token); |
|
30 | 1 | if (!$token) { |
|
31 | return false; |
||
32 | } |
||
33 | |||
34 | 1 | return $token->check($data); |
|
35 | } |
||
36 | |||
37 | 2 | public function findToken($token) |
|
38 | { |
||
39 | 2 | if ($token instanceof Token) { |
|
40 | 1 | return $token; |
|
41 | } |
||
42 | |||
43 | 2 | $data = $this->readToken($token); |
|
44 | |||
45 | 2 | return empty($data) ? null : new Token($this, $data, $token); |
|
46 | } |
||
47 | |||
48 | public function removeToken($token) |
||
49 | { |
||
50 | return $this->getStorage()->remove((string) $token); |
||
0 ignored issues
–
show
|
|||
51 | } |
||
52 | |||
53 | 2 | protected function readToken($string) |
|
54 | { |
||
55 | 2 | return $this->getStorage()->has($string) ? json_decode($this->getStorage()->get($string), true) : null; |
|
0 ignored issues
–
show
It seems like
getStorage() must be provided by classes using this trait. How about adding it as abstract method to this trait?
This check looks for methods that are used by a trait but not required by it. To illustrate, let’s look at the following code example trait Idable {
public function equalIds(Idable $other) {
return $this->getId() === $other->getId();
}
}
The trait Adding the
Loading history...
|
|||
56 | } |
||
57 | |||
58 | 3 | protected function writeToken(Token $token) |
|
59 | { |
||
60 | 3 | return $this->getStorage()->set((string) $token, json_encode($token->mget())); |
|
0 ignored issues
–
show
It seems like
getStorage() must be provided by classes using this trait. How about adding it as abstract method to this trait?
This check looks for methods that are used by a trait but not required by it. To illustrate, let’s look at the following code example trait Idable {
public function equalIds(Idable $other) {
return $this->getId() === $other->getId();
}
}
The trait Adding the
Loading history...
|
|||
61 | } |
||
62 | } |
||
63 |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.