StackProcessor::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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