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

IdentityCollector   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

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

4 Methods

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