Completed
Pull Request — develop (#65)
by
unknown
47:03 queued 18:26
created

RaListingSearchQuery::setInstitution()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
/**
4
 * Copyright 2014 SURFnet bv
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
namespace Surfnet\StepupMiddlewareClient\Identity\Dto;
20
21
use Assert;
22
use Surfnet\StepupMiddlewareClient\Dto\HttpQuery;
23
24
final class RaListingSearchQuery implements HttpQuery
25
{
26
    /**
27
     * @var string
28
     */
29
    private $actorInstitution;
30
31
    /**
32
     * @var string|null
33
     */
34
    private $institution;
35
36
    /**
37
     * @var int
38
     */
39
    private $pageNumber;
40
41
    /**
42
     * @var string|null
43
     */
44
    private $orderBy = 'commonName';
45
46
    /**
47
     * @var string|null
48
     */
49
    private $orderDirection = 'asc';
50
51
    /**
52
     * @param string $institution
0 ignored issues
show
Documentation introduced by
There is no parameter named $institution. Did you maybe mean $actorInstitution?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
53
     * @param int    $pageNumber
54
     */
55 View Code Duplication
    public function __construct($actorInstitution, $pageNumber)
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...
56
    {
57
        $this->assertNonEmptyString($actorInstitution, 'actorInstitution');
58
        Assert\that($pageNumber)
59
            ->integer('Page number must be an integer')
60
            ->min(0, 'Page number must be greater than or equal to 1');
61
62
        $this->actorInstitution = $actorInstitution;
63
        $this->pageNumber  = $pageNumber;
64
    }
65
66
    /**
67
     * @param string $institution
68
     * @return $this
69
     */
70
    public function setInstitution($institution)
71
    {
72
        $this->assertNonEmptyString($institution, 'institution');
73
74
        $this->institution = $institution;
75
76
        return $this;
77
    }
78
79
    /**
80
     * @param string $orderBy
81
     * @return RaListingSearchQuery
82
     */
83
    public function setOrderBy($orderBy)
84
    {
85
        $this->assertNonEmptyString($orderBy, 'orderBy');
86
87
        $this->orderBy = $orderBy;
88
89
        return $this;
90
    }
91
92
    /**
93
     * @param string|null $orderDirection
94
     * @return RaListingSearchQuery
95
     */
96 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...
97
    {
98
        Assert\that($orderDirection)->choice(
99
            ['asc', 'desc', '', null],
100
            "Invalid order direction, must be one of 'asc', 'desc'"
101
        );
102
103
        $this->orderDirection = $orderDirection ?: null;
104
105
        return $this;
106
    }
107
108
    private function assertNonEmptyString($value, $parameterName)
109
    {
110
        $message = sprintf(
111
            '"%s" must be a non-empty string, "%s" given',
112
            $parameterName,
113
            (is_object($value) ? get_class($value) : gettype($value))
114
        );
115
116
        Assert\that($value)->string($message)->notEmpty($message);
117
    }
118
119
    public function toHttpQuery()
120
    {
121
        return '?' . http_build_query(
122
            array_filter(
123
                [
124
                    'actorInstitution' => $this->actorInstitution,
125
                    'institution'      => $this->institution,
126
                    'orderBy'          => $this->orderBy,
127
                    'orderDirection'   => $this->orderDirection,
128
                    'p'                => $this->pageNumber,
129
                ],
130
                function ($value) {
131
                    return !is_null($value);
132
                }
133
            )
134
        );
135
    }
136
}
137