Test Failed
Push — master ( 056488...5ae6d5 )
by Florian
10:43 queued 07:19
created

StackProcessor::add()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
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
    public function __construct(array $processors)
33
    {
34
        foreach ($processors as $processor) {
35
            $this->add($processor);
36
        }
37
    }
38
39
    /**
40
     * @param \Phauthentic\Infrastructure\Storage\Processor\ProcessorInterface $processor
41
     */
42
    public function add(ProcessorInterface $processor): void
43
    {
44
        $this->processors[] = $processor;
45
    }
46
47
    /**
48
     * @inheritdoc
49
     */
50
    public function process(FileInterface $file): FileInterface
51
    {
52
        foreach ($this->processors as $processor) {
53
            $file = $processor->process($file);
54
        }
55
56
        return $file;
57
    }
58
}
59