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

IdentityCollector   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getCollected() 0 3 1
A reset() 0 3 1
A collect() 0 13 3
A getSummary() 0 7 2
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