Passed
Pull Request — master (#66)
by Dmitriy
41:45 queued 29:40
created

IdentityCollector   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 94.74%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 39
ccs 18
cts 19
cp 0.9474
rs 10
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getCollected() 0 3 1
A getSummary() 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\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 1
    public function getCollected(): array
18
    {
19 1
        return $this->identities;
20
    }
21
22 1
    public function collect(?IdentityInterface $identity): void
23
    {
24 1
        if (!$this->isActive()) {
25
            return;
26
        }
27
28 1
        if ($identity === null) {
29 1
            return;
30
        }
31
32 1
        $this->identities[] = [
33 1
            'id' => $identity->getId(),
34 1
            'class' => $identity::class,
35 1
        ];
36
    }
37
38 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...
39
    {
40 1
        $this->identities = [];
41
    }
42
43 1
    public function getSummary(): array
44
    {
45 1
        $lastIdentity = end($this->identities);
46 1
        return [
47 1
            'identity' => [
48 1
                'lastId' => is_array($lastIdentity) ? $lastIdentity['id'] : null,
49 1
                'total' => count($this->identities),
50 1
            ],
51 1
        ];
52
    }
53
}
54