These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | /* |
||
4 | * Library for confirmation tokens |
||
5 | * |
||
6 | * @link https://github.com/hiqdev/php-confirmator |
||
7 | * @package php-confirmator |
||
8 | * @license BSD-3-Clause |
||
9 | * @copyright Copyright (c) 2016, HiQDev (http://hiqdev.com/) |
||
10 | */ |
||
11 | |||
12 | namespace hiqdev\php\confirmator; |
||
13 | |||
14 | trait ServiceTrait |
||
15 | { |
||
16 | 3 | public function issueToken(array $data) |
|
17 | { |
||
18 | 3 | $token = new Token($this, $data); |
|
19 | 3 | $this->writeToken($token); |
|
20 | |||
21 | 3 | return $token; |
|
22 | } |
||
23 | |||
24 | 1 | public function checkToken($token, array $data) |
|
25 | { |
||
26 | 1 | $token = $this->findToken($token); |
|
27 | 1 | if (!$token) { |
|
28 | return false; |
||
29 | } |
||
30 | |||
31 | 1 | return $token->check($data); |
|
32 | } |
||
33 | |||
34 | 2 | public function findToken($token) |
|
35 | { |
||
36 | 2 | if ($token instanceof Token) { |
|
37 | 1 | return $token; |
|
38 | } |
||
39 | |||
40 | 2 | $data = $this->readToken($token); |
|
41 | |||
42 | 2 | return empty($data) ? null : new Token($this, $data, $token); |
|
43 | } |
||
44 | |||
45 | public function removeToken($token) |
||
46 | { |
||
47 | return $this->getStorage()->remove((string) $token); |
||
0 ignored issues
–
show
|
|||
48 | } |
||
49 | |||
50 | 2 | protected function readToken($string) |
|
51 | { |
||
52 | 2 | return $this->getStorage()->has($string) ? json_decode($this->getStorage()->get($string), true) : null; |
|
53 | } |
||
54 | |||
55 | 3 | protected function writeToken(Token $token) |
|
56 | { |
||
57 | 3 | return $this->getStorage()->set((string) $token, json_encode($token->mget())); |
|
58 | } |
||
59 | } |
||
60 |
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.