IdentityCollector   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 21
c 1
b 0
f 0
dl 0
loc 45
ccs 23
cts 23
cp 1
rs 10
wmc 9

4 Methods

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