Completed
Push — feature/ra-locations ( 8e7bb5...72222c )
by Boy
14:46 queued 11:53
created

RaLocationSearchQuery   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 75
Duplicated Lines 29.33 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 6
c 1
b 0
f 1
lcom 1
cbo 1
dl 22
loc 75
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A setOrderBy() 0 8 1
A setOrderDirection() 12 12 1
A assertNonEmptyString() 10 10 2
A toHttpQuery() 0 6 1

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 Surfnet\StepupMiddlewareClient\Configuration\Dto;
4
5
use Assert;
6
use Surfnet\StepupMiddlewareClient\Dto\HttpQuery;
7
8
class RaLocationSearchQuery implements HttpQuery
9
{
10
    /**
11
     * @var string
12
     */
13
    private $institution;
14
15
    /**
16
     * @var string|null
17
     */
18
    private $orderBy = 'name';
19
20
    /**
21
     * @var string|null
22
     */
23
    private $orderDirection = 'asc';
24
25
    /**
26
     * @param string $institution
27
     */
28
    public function __construct($institution)
29
    {
30
        $this->assertNonEmptyString($institution, 'institution');
31
32
        $this->institution = $institution;
33
    }
34
35
    /**
36
     * @param string $orderBy
37
     * @return $this
38
     */
39
    public function setOrderBy($orderBy)
40
    {
41
        $this->assertNonEmptyString($orderBy, 'orderBy');
42
43
        $this->orderBy = $orderBy;
44
45
        return $this;
46
    }
47
48
    /**
49
     * @param string $orderDirection
50
     * @return $this
51
     */
52 View Code Duplication
    public function setOrderDirection($orderDirection)
0 ignored issues
show
Duplication introduced by
This method 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...
53
    {
54
        $this->assertNonEmptyString($orderDirection, 'orderDirection');
55
        Assert\that($orderDirection)->choice(
56
            ['asc', 'desc', '', null],
57
            "Invalid order direction, must be one of 'asc', 'desc'"
58
        );
59
60
        $this->orderDirection = $orderDirection;
61
62
        return $this;
63
    }
64
65 View Code Duplication
    private function assertNonEmptyString($value, $name)
0 ignored issues
show
Duplication introduced by
This method 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...
66
    {
67
        $message = sprintf(
68
            '"%s" must be a non-empty string, "%s" given',
69
            $name,
70
            (is_object($value) ? get_class($value) : gettype($value))
71
        );
72
73
        Assert\that($value)->string($message)->notEmpty($message);
74
    }
75
76
    public function toHttpQuery()
77
    {
78
        return '/' . $this->institution
79
            . '?orderBy=' . urlencode($this->orderBy)
80
            . '&orderDirection' . urlencode($this->orderDirection);
81
    }
82
}
83