Completed
Push — master ( 6d43d4...4e69d5 )
by Nikola
02:46
created

RotatorCollection::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
/*
3
 * This file is part of the Backup package, an RunOpenCode project.
4
 *
5
 * (c) 2015 RunOpenCode
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * This project is fork of "kbond/php-backup", for full credits info, please
11
 * view CREDITS file that was distributed with this source code.
12
 */
13
namespace RunOpenCode\Backup\Rotator;
14
15
use RunOpenCode\Backup\Contract\RotatorInterface;
16
17
/**
18
 * Class RotatorCollection
19
 *
20
 * Rotator collection consults several rotators for nomination.
21
 *
22
 * @package RunOpenCode\Backup\Rotator
23
 */
24
class RotatorCollection implements \IteratorAggregate, RotatorInterface
25
{
26
    /**
27
     * @var RotatorInterface[]
28
     */
29
    private $rotators;
30
31 2
    public function __construct(array $rotators = array())
32
    {
33 2
        $this->rotators = $rotators;
34 2
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39 2
    public function nominate(array $backups)
40
    {
41 2
        $result = array();
42
43
        /** @var RotatorInterface $rotator */
44 2
        foreach ($this->rotators as $rotator) {
45
46 2
            foreach ($rotator->nominate($backups) as $nomination) {
47
48 2
                if (!in_array($nomination, $result)) {
49 2
                    $result[] = $nomination;
50 2
                }
51 2
            }
52 2
        }
53
54 2
        return $result;
55
    }
56
57
    /**
58
     * {@inheritdoc}
59
     */
60
    public function getIterator()
61
    {
62
        return new \ArrayIterator($this->rotators);
63
    }
64
}
65