Completed
Push — master ( 4ddb4f...b811e8 )
by Nikola
02:20
created

ProcessorCollection::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 8
ccs 7
cts 7
cp 1
rs 9.4286
cc 2
eloc 4
nc 2
nop 1
crap 2
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\Processor;
14
15
use RunOpenCode\Backup\Contract\ProcessorInterface;
16
17
final class ProcessorCollection implements ProcessorInterface, \IteratorAggregate
18
{
19
    /**
20
     * @var ProcessorInterface[]
21
     */
22
    private $processors;
23
24 2
    public function __construct(array $processors = array())
25 2
    {
26 2
        $this->processors = array();
27
28 2
        foreach ($processors as $processor) {
29 2
            $this->add($processor);
30 2
        }
31 2
    }
32
33
    /**
34
     * Add processor to collection
35
     *
36
     * @param ProcessorInterface $processor Processor to add to collection.
37
     * @return ProcessorCollection $this Fluent interface.
38
     */
39 2
    public function add(ProcessorInterface $processor)
40
    {
41 2
        $this->processors[] = $processor;
42 2
        return $this;
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48 2
    public function process(array $files)
49
    {
50 2
        foreach ($this->processors as $processor) {
51 2
            $files = $processor->process($files);
52 2
        }
53
54 2
        return $files;
55
    }
56
57
    /**
58
     * {@inheritdoc}
59
     */
60
    public function getIterator()
61
    {
62
        return new \ArrayIterator($this->processors);
63
    }
64
}
65