IdentifierCollection::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
/**
4
 * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
5
 * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
6
 *
7
 * Licensed under The MIT License
8
 * For full copyright and license information, please see the LICENSE.txt
9
 * Redistributions of files must retain the above copyright notice.
10
 *
11
 * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
12
 * @link          https://cakephp.org CakePHP(tm) Project
13
 * @since         1.0.0
14
 * @license       https://opensource.org/licenses/mit-license.php MIT License
15
 */
16
17
declare(strict_types=1);
18
19
namespace Phauthentic\Authentication\Identifier;
20
21
use ArrayIterator;
22
use Traversable;
23
24
/**
25
 * Identifier Collection
26
 */
27
class IdentifierCollection implements IdentifierCollectionInterface
28
{
29
    /**
30
     * Identifier list
31
     *
32
     * @var array<\Phauthentic\Authentication\Identifier\IdentifierInterface>
33
     */
34
    protected array $identifiers;
35
36
    /**
37
     * Constructor
38
     *
39 16
     * @param iterable<\Phauthentic\Authentication\Identifier\IdentifierInterface> $identifiers Identifier objects.
40
     */
41 16
    public function __construct(iterable $identifiers = [])
42 4
    {
43
        foreach ($identifiers as $identifier) {
44 16
            $this->add($identifier);
45
        }
46
    }
47
48
    /**
49
     * Adds an identifier to the collection
50
     *
51
     * @param IdentifierInterface $identifier Identifier
52 16
     * @return void
53
     */
54 16
    public function add(IdentifierInterface $identifier): void
55 16
    {
56
        $this->identifiers[] = $identifier;
57
    }
58
59
    /**
60
     * Returns true if a collection is empty.
61
     *
62 8
     * @return bool
63
     */
64 8
    public function isEmpty(): bool
65
    {
66
        return empty($this->identifiers);
67
    }
68
69
    /**
70
     * Returns iterator.
71
     *
72 8
     * @return \ArrayIterator
73
     */
74 8
    public function getIterator(): Traversable
75
    {
76
        return new ArrayIterator($this->identifiers);
77
    }
78
}
79