Passed
Push — master ( f7ef7a...65c26d )
by Dmitriy
02:46
created

IdentityCollector::getSummary()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
c 0
b 0
f 0
dl 0
loc 7
rs 10
cc 2
nc 2
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Debug\Collector\Web;
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
    public function getCollected(): array
18
    {
19
        return $this->identities;
20
    }
21
22
    public function collect(?IdentityInterface $identity): void
23
    {
24
        if (!$this->isActive()) {
25
            return;
26
        }
27
28
        if ($identity === null) {
29
            return;
30
        }
31
32
        $this->identities[] = [
33
            'id' => $identity->getId(),
34
            'class' => $identity::class,
35
        ];
36
    }
37
38
    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...
39
    {
40
        $this->identities = [];
41
    }
42
43
    public function getSummary(): array
44
    {
45
        $lastIdentity = end($this->identities);
46
        return [
47
            'identity' => [
48
                'lastId' => is_array($lastIdentity) ? $lastIdentity['id'] : null,
49
                'total' => count($this->identities),
50
            ],
51
        ];
52
    }
53
}
54