Passed
Push — master ( f8dc65...03c53a )
by Dmitriy
03:28 queued 59s
created

IdentityCollector   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 17
c 1
b 0
f 0
dl 0
loc 39
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A collect() 0 13 3
A reset() 0 3 1
A getIndexData() 0 7 2
A getCollected() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Debug\Collector;
6
7
use Yiisoft\Auth\IdentityInterface;
8
9
final class IdentityCollector implements CollectorInterface, IndexCollectorInterface
10
{
11
    use CollectorTrait;
12
13
    private array $identities = [];
14
15
    public function getCollected(): array
16
    {
17
        return $this->identities;
18
    }
19
20
    public function collect(?IdentityInterface $identity): void
21
    {
22
        if (!$this->isActive()) {
23
            return;
24
        }
25
26
        if ($identity === null) {
27
            return;
28
        }
29
30
        $this->identities[] = [
31
            'id' => $identity->getId(),
32
            'class' => $identity::class,
33
        ];
34
    }
35
36
    private function reset(): void
0 ignored issues
show
Unused Code introduced by
The method reset() is not used, and could be removed.

This check looks for private methods that have been defined, but are not used inside the class.

Loading history...
37
    {
38
        $this->identities = [];
39
    }
40
41
    public function getIndexData(): array
42
    {
43
        $lastIdentity = end($this->identities);
44
        return [
45
            'identity' => [
46
                'lastId' => is_array($lastIdentity) ? $lastIdentity['id'] : null,
47
                'total' => count($this->identities),
48
            ],
49
        ];
50
    }
51
}
52