Passed
Pull Request — master (#66)
by Dmitriy
08:25 queued 06:17
created

IdentityCollector::reset()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
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 1
    public function getCollected(): array
19
    {
20 1
        return $this->identities;
21
    }
22
23 1
    public function collect(?IdentityInterface $identity): void
24
    {
25 1
        if (!$this->isActive()) {
26
            return;
27
        }
28
29 1
        if ($identity === null) {
30 1
            return;
31
        }
32
33 1
        $this->identities[] = [
34 1
            'id' => $identity->getId(),
35 1
            'class' => $identity::class,
36 1
        ];
37
    }
38
39 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...
40
    {
41 1
        $this->identities = [];
42
    }
43
44 1
    public function getIndexData(): array
45
    {
46 1
        $lastIdentity = end($this->identities);
47 1
        return [
48 1
            'identity' => [
49 1
                'lastId' => is_array($lastIdentity) ? $lastIdentity['id'] : null,
50 1
                'total' => count($this->identities),
51 1
            ],
52 1
        ];
53
    }
54
}
55