1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace Yiisoft\Auth\Debug; |
||
6 | |||
7 | use Yiisoft\Auth\IdentityInterface; |
||
8 | use Yiisoft\Yii\Debug\Collector\CollectorTrait; |
||
9 | use Yiisoft\Yii\Debug\Collector\SummaryCollectorInterface; |
||
10 | |||
11 | final class IdentityCollector implements SummaryCollectorInterface |
||
12 | { |
||
13 | use CollectorTrait; |
||
14 | |||
15 | private array $identities = []; |
||
16 | |||
17 | 3 | public function getCollected(): array |
|
18 | { |
||
19 | 3 | if (!$this->isActive()) { |
|
20 | 2 | return []; |
|
21 | } |
||
22 | 1 | return $this->identities; |
|
23 | } |
||
24 | |||
25 | 2 | public function collect(?IdentityInterface $identity): void |
|
26 | { |
||
27 | 2 | if (!$this->isActive()) { |
|
28 | 1 | return; |
|
29 | } |
||
30 | |||
31 | 1 | if ($identity === null) { |
|
32 | 1 | return; |
|
33 | } |
||
34 | |||
35 | 1 | $this->identities[] = [ |
|
36 | 1 | 'id' => $identity->getId(), |
|
37 | 1 | 'class' => $identity::class, |
|
38 | 1 | ]; |
|
39 | } |
||
40 | |||
41 | 1 | private function reset(): void |
|
0 ignored issues
–
show
|
|||
42 | { |
||
43 | 1 | $this->identities = []; |
|
44 | } |
||
45 | |||
46 | 3 | public function getSummary(): array |
|
47 | { |
||
48 | 3 | if (!$this->isActive()) { |
|
49 | 2 | return []; |
|
50 | } |
||
51 | 1 | $lastIdentity = end($this->identities); |
|
52 | 1 | return [ |
|
53 | 1 | 'identity' => [ |
|
54 | 1 | 'lastId' => is_array($lastIdentity) ? $lastIdentity['id'] : null, |
|
55 | 1 | 'total' => count($this->identities), |
|
56 | 1 | ], |
|
57 | 1 | ]; |
|
58 | } |
||
59 | } |
||
60 |
This check looks for private methods that have been defined, but are not used inside the class.