RequestModifierCollection::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 8
Ratio 100 %

Code Coverage

Tests 6
CRAP Score 1
Metric Value
dl 8
loc 8
ccs 6
cts 6
cp 1
rs 9.4285
cc 1
eloc 5
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Thruster\Component\HttpModifier;
4
5
use Psr\Http\Message\RequestInterface;
6
7
/**
8
 * Class RequestModifierCollection
9
 *
10
 * @package Thruster\Component\HttpModifier
11
 * @author  Aurimas Niekis <[email protected]>
12
 */
13 View Code Duplication
class RequestModifierCollection extends BaseModifierCollection implements RequestModifierInterface
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 RequestModifierInterface[] $modifiers
17
     */
18 3
    public function __construct(array $modifiers = [])
19
    {
20 3
        parent::__construct();
21
22 3
        $this->collection = (function (RequestModifierInterface ...$modifiers) {
23 3
            return $modifiers;
24 3
        })(...$modifiers);
25 3
    }
26
27
    /***
28
     * @param RequestModifierInterface $modifier
29
     *
30
     * @return $this
31
     */
32 2
    public function add(RequestModifierInterface $modifier)
33
    {
34 2
        $this->collection[] = $modifier;
35
36 2
        return $this;
37
    }
38
39
    /**
40
     * @param RequestInterface $request
41
     *
42
     * @return RequestInterface
43
     */
44 1
    public function modify(RequestInterface $request) : RequestInterface
45
    {
46
        /** @var RequestModifierInterface $modifier */
47 1
        foreach ($this->collection as $modifier) {
48 1
            $request = $modifier->modify($request);
49
        }
50
51 1
        return $request;
52
    }
53
}
54