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

StackProcessor   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 32
ccs 11
cts 11
cp 1
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 7 2
A __construct() 0 4 2
A add() 0 3 1
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