HeaderLocation   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 55
Duplicated Lines 12.73 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 3
dl 7
loc 55
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A visit() 0 9 1
A after() 7 17 5

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
namespace GuzzleHttp\Command\Guzzle\RequestLocation;
3
4
use GuzzleHttp\Command\CommandInterface;
5
use GuzzleHttp\Command\Guzzle\Operation;
6
use GuzzleHttp\Command\Guzzle\Parameter;
7
use Psr\Http\Message\MessageInterface;
8
use Psr\Http\Message\RequestInterface;
9
10
/**
11
 * Request header location
12
 */
13
class HeaderLocation extends AbstractLocation
14
{
15
16
    /**
17
     * Set the name of the location
18
     *
19
     * @param string $locationName
20
     */
21 2
    public function __construct($locationName = 'header')
22
    {
23 2
        parent::__construct($locationName);
24 2
    }
25
26
    /**
27
     * @param CommandInterface $command
28
     * @param RequestInterface $request
29
     * @param Parameter        $param
30
     *
31
     * @return MessageInterface
32
     */
33 1
    public function visit(
34
        CommandInterface $command,
35
        RequestInterface $request,
36
        Parameter $param
37
    ) {
38 1
        $value = $command[$param->getName()];
0 ignored issues
show
Bug introduced by
Consider using $param->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
39
40 1
        return $request->withHeader($param->getWireName(), $param->filter($value));
41
    }
42
43
    /**
44
     * @param CommandInterface $command
45
     * @param RequestInterface $request
46
     * @param Operation        $operation
47
     *
48
     * @return RequestInterface
49
     */
50 1
    public function after(
51
        CommandInterface $command,
52
        RequestInterface $request,
53
        Operation $operation
54
    ) {
55
        /** @var Parameter $additional */
56 1
        $additional = $operation->getAdditionalParameters();
57 1 View Code Duplication
        if ($additional && ($additional->getLocation() === $this->locationName)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
58 1
            foreach ($command->toArray() as $key => $value) {
59 1
                if (!$operation->hasParam($key)) {
60 1
                    $request = $request->withHeader($key, $additional->filter($value));
61 1
                }
62 1
            }
63 1
        }
64
65 1
        return $request;
66
    }
67
}
68