ResponseModifierCollection::__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\ResponseInterface;
6
7
/**
8
 * Class ResponseModifierCollection
9
 *
10
 * @package Thruster\Component\HttpModifier
11
 * @author  Aurimas Niekis <[email protected]>
12
 */
13 View Code Duplication
class ResponseModifierCollection extends BaseModifierCollection implements ResponseModifierInterface
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 ResponseModifierInterface[] $modifiers
17
     */
18 3
    public function __construct(array $modifiers = [])
19
    {
20 3
        parent::__construct();
21
22 3
        $this->collection = (function (ResponseModifierInterface ...$modifiers) {
23 3
            return $modifiers;
24 3
        })(...$modifiers);
25 3
    }
26
27
    /***
28
     * @param ResponseModifierInterface $modifier
29
     *
30
     * @return $this
31
     */
32 2
    public function add(ResponseModifierInterface $modifier)
33
    {
34 2
        $this->collection[] = $modifier;
35
36 2
        return $this;
37
    }
38
39
    /**
40
     * @param ResponseInterface $response
41
     *
42
     * @return ResponseInterface
43
     */
44 1
    public function modify(ResponseInterface $response) : ResponseInterface
45
    {
46
        /** @var ResponseModifierInterface $modifier */
47 1
        foreach ($this->collection as $modifier) {
48 1
            $response = $modifier->modify($response);
49
        }
50
51 1
        return $response;
52
    }
53
}
54