IdentityCollector::getSummary()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 7
c 0
b 0
f 0
nc 3
nop 0
dl 0
loc 10
ccs 8
cts 8
cp 1
crap 3
rs 10
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