ServerRequestModifierCollection::modify()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 9
Ratio 100 %

Code Coverage

Tests 4
CRAP Score 2
Metric Value
dl 9
loc 9
ccs 4
cts 4
cp 1
rs 9.6666
cc 2
eloc 4
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Thruster\Component\HttpModifier;
4
5
use Psr\Http\Message\ServerRequestInterface;
6
7
/**
8
 * Class ServerRequestModifierCollection
9
 *
10
 * @package Thruster\Component\HttpModifier
11
 * @author  Aurimas Niekis <[email protected]>
12
 */
13 View Code Duplication
class ServerRequestModifierCollection extends BaseModifierCollection implements ServerRequestModifierInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
14
{
15
    /**
16
     * @param ServerRequestModifierInterface[] $modifiers
17
     */
18 3
    public function __construct(array $modifiers = [])
19
    {
20 3
        parent::__construct();
21
22 3
        $this->collection = (function (ServerRequestModifierInterface ...$modifiers) {
23 3
            return $modifiers;
24 3
        })(...$modifiers);
25 3
    }
26
27
    /***
28
     * @param ServerRequestModifierInterface $modifier
29
     *
30
     * @return $this
31
     */
32 2
    public function add(ServerRequestModifierInterface $modifier)
33
    {
34 2
        $this->collection[] = $modifier;
35
36 2
        return $this;
37
    }
38
39
    /**
40
     * @param ServerRequestInterface $request
41
     *
42
     * @return ServerRequestInterface
43
     */
44 1
    public function modify(ServerRequestInterface $request) : ServerRequestInterface
45
    {
46
        /** @var ServerRequestModifierInterface $modifier */
47 1
        foreach ($this->collection as $modifier) {
48 1
            $request = $modifier->modify($request);
49
        }
50
51 1
        return $request;
52
    }
53
}
54