Test Failed
Pull Request — master (#66)
by Dmitriy
04:33 queued 02:18
created

IdentityCollector::getIndexData()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 7
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\CollectorInterface;
9
use Yiisoft\Yii\Debug\Collector\CollectorTrait;
10
use Yiisoft\Yii\Debug\Collector\IndexCollectorInterface;
11
12
final class IdentityCollector implements CollectorInterface, IndexCollectorInterface
13
{
14
    use CollectorTrait;
15
16
    private array $identities = [];
17
18
    public function getCollected(): array
19
    {
20
        return $this->identities;
21
    }
22
23
    public function collect(?IdentityInterface $identity): void
24
    {
25
        if (!$this->isActive()) {
26
            return;
27
        }
28
29
        if ($identity === null) {
30
            return;
31
        }
32
33
        $this->identities[] = [
34
            'id' => $identity->getId(),
35
            'class' => $identity::class,
36
        ];
37
    }
38
39
    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...
40
    {
41
        $this->identities = [];
42
    }
43
44
    public function getIndexData(): array
45
    {
46
        $lastIdentity = end($this->identities);
47
        return [
48
            'identity' => [
49
                'lastId' => is_array($lastIdentity) ? $lastIdentity['id'] : null,
50
                'total' => count($this->identities),
51
            ],
52
        ];
53
    }
54
}
55