ServerRequestModifierCollection   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%
Metric Value
wmc 4
lcom 1
cbo 1
dl 41
loc 41
ccs 13
cts 13
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 8 8 1
A add() 6 6 1
A modify() 9 9 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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