Passed
Push — develop ( a2f470...25a8d0 )
by Florian
07:16
created

StackProcessor::process()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 2
rs 10
1
<?php
2
3
/**
4
 * Copyright (c) Florian Krämer (https://florian-kraemer.net)
5
 * Licensed under The MIT License
6
 * For full copyright and license information, please see the LICENSE.txt
7
 * Redistributions of files must retain the above copyright notice.
8
 *
9
 * @copyright Copyright (c) Florian Krämer (https://florian-kraemer.net)
10
 * @author    Florian Krämer
11
 * @link      https://github.com/Phauthentic
12
 * @license   https://opensource.org/licenses/MIT MIT License
13
 */
14
15
declare(strict_types=1);
16
17
namespace Phauthentic\Infrastructure\Storage\Processor;
18
19
use Phauthentic\Infrastructure\Storage\FileInterface;
20
21
/**
22
 * The stack processor takes a list of other processors and processes them in
23
 * the order they were added to the stack.
24
 */
25
class StackProcessor implements ProcessorInterface
26
{
27
    protected array $processors = [];
28
29
    /**
30
     * @param \Phauthentic\Infrastructure\Storage\Processor\ProcessorInterface[] $processors
31
     */
32 1
    public function __construct(array $processors)
33
    {
34 1
        foreach ($processors as $processor) {
35 1
            $this->add($processor);
36
        }
37 1
    }
38
39
    /**
40
     * @param \Phauthentic\Infrastructure\Storage\Processor\ProcessorInterface $processor
41
     */
42 1
    public function add(ProcessorInterface $processor): void
43
    {
44 1
        $this->processors[] = $processor;
45 1
    }
46
47
    /**
48
     * @inheritdoc
49
     */
50 1
    public function process(FileInterface $file): FileInterface
51
    {
52 1
        foreach ($this->processors as $processor) {
53 1
            $file = $processor->process($file);
54
        }
55
56 1
        return $file;
57
    }
58
}
59