GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

RequestDataSet::getAdditionalRequestDataSet()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace JDolba\SlimHttpSmokeTesting;
5
6
use JDolba\SlimHttpSmokeTesting\RouteConfiguration\RouteConfigurationInterface;
7
use JDolba\SlimHttpSmokeTesting\RouterAdapter\RouterAdapterInterface;
8
use Slim\Http\Environment;
9
use Slim\Http\Request;
10
11
class RequestDataSet
12
{
13
    const DEFAULT_EXPECTED_HTTP_CODE_OK = 200;
14
15
    /**
16
     * @var int
17
     */
18
    private $expectedHttpCode = self::DEFAULT_EXPECTED_HTTP_CODE_OK;
19
    /**
20
     * @var \JDolba\SlimHttpSmokeTesting\RouteConfiguration\RouteConfigurationInterface
21
     */
22
    private $routeConfiguration;
23
    /**
24
     * @var string
25
     */
26
    private $method;
27
    /**
28
     * @var bool
29
     */
30
    private $skipped;
31
    /**
32
     * @var null|string
33
     */
34
    private $skippedReason;
35
    /**
36
     * @var string[]
37
     */
38
    private $uriParamsForRouter = [];
39
    /**
40
     * @var string[]
41
     */
42
    private $queryParamsForRouter = [];
43
    /**
44
     * @var callable
45
     */
46
    private $requestPromise;
47
    /**
48
     * @var null|callable
49
     */
50
    private $authenticationCallable;
51
    /**
52
     * @var self[]
53
     */
54
    private $additionalRequestDataSets = [];
55
56
    public function __construct(RouteConfigurationInterface $routeConfiguration, string $method)
57
    {
58
        $this->method = $method;
59
        $this->routeConfiguration = $routeConfiguration;
60
        $this->asNotSkipped();
61
        $this->requestPromise = $this->createDefaultRequestPromise();
62
    }
63
64
    public function createDefaultRequestPromise()
65
    {
66
        return function (RouterAdapterInterface $routerAdapter, RequestDataSet $requestDataSet) {
67
            $uri = $routerAdapter->generateRelativePath(
68
                $requestDataSet->getRouteConfiguration(),
69
                $requestDataSet->getUriParamsForRouter(),
70
                $requestDataSet->getQueryParamsForRouter()
71
            );
72
73
            $env = Environment::mock(
74
                [
75
                    'REQUEST_METHOD' => $requestDataSet->getMethod(),
76
                    'REQUEST_URI' => $uri,
77
                ]
78
            );
79
80
            return Request::createFromEnvironment($env);
81
        };
82
    }
83
84
    /**
85
     * @return string
86
     */
87 3
    public function getMethod(): string
88
    {
89 3
        return $this->method;
90
    }
91
92
    public function getUriParamsForRouter(): array
93
    {
94
        return $this->uriParamsForRouter;
95
    }
96
97
    public function setUriParamsForRouter(array $uriParams)
98
    {
99
        $this->uriParamsForRouter = $uriParams;
100
    }
101
102
    public function getQueryParamsForRouter(): array
103
    {
104
        return $this->queryParamsForRouter;
105
    }
106
107
    public function setQueryParamsForRouter(array $queryParams)
108
    {
109
        $this->queryParamsForRouter = $queryParams;
110
    }
111
112
    /**
113
     * @return \JDolba\SlimHttpSmokeTesting\RouteConfiguration\RouteConfigurationInterface
114
     */
115
    public function getRouteConfiguration(): RouteConfigurationInterface
116
    {
117
        return $this->routeConfiguration;
118
    }
119
120
    /**
121
     * @return int
122
     */
123 3
    public function getExpectedHttpCode(): int
124
    {
125 3
        return $this->expectedHttpCode;
126
    }
127
128
    /**
129
     * @param int $code
130
     */
131 3
    public function setExpectedHttpCode(int $code)
132
    {
133 3
        $this->expectedHttpCode = $code;
134 3
    }
135
136
    /**
137
     * @param string|null $why
138
     */
139 3
    public function skip(string $why = null)
140
    {
141 3
        $this->skipped = true;
142 3
        $this->skippedReason = $why;
143 3
    }
144
145
    public function asNotSkipped()
146
    {
147
        $this->skipped = false;
148
        $this->skippedReason = null;
149
    }
150
151
    /**
152
     * @return bool
153
     */
154 3
    public function isSkipped(): bool
155
    {
156 3
        return $this->skipped;
157
    }
158
159
    /**
160
     * @return null|string
161
     */
162
    public function getSkippedReason(): ?string
163
    {
164
        return $this->skippedReason;
165
    }
166
167
    /**
168
     * arguments of callable will be:
169
     * + \JDolba\SlimHttpSmokeTesting\RouterAdapter\RouterAdapterInterface $routerAdapter
170
     * + \JDolba\SlimHttpSmokeTesting\RequestDataSet $requestDataSet ($this)
171
     *
172
     * @see \JDolba\SlimHttpSmokeTesting\RequestDataSet::__construct
173
     *
174
     * @param callable $callable
175
     */
176
    public function setRequestPromise(callable $callable)
177
    {
178
        $this->requestPromise = $callable;
179
    }
180
181
    /**
182
     * @return callable
183
     */
184
    public function getRequestPromise(): callable
185
    {
186
        return $this->requestPromise;
187
    }
188
189
    /**
190
     * @param string|null $method if null, value of $method from parent(this) will be used
191
     * @return self new instance for additional request on same route
192
     */
193
    public function addNewExtraRequestDataSet(string $method = null)
194
    {
195
        $newRequestDataSet = new self(
196
            $this->getRouteConfiguration(),
197
            $method === null ? $this->getMethod() : $method
198
        );
199
200
        $this->additionalRequestDataSets[] = $newRequestDataSet;
201
202
        return $newRequestDataSet;
203
    }
204
205
    /**
206
     * @return \JDolba\SlimHttpSmokeTesting\RequestDataSet[]
207
     */
208
    public function getAdditionalRequestDataSet(): array
209
    {
210
        return $this->additionalRequestDataSets;
211
    }
212
213
    /**
214
     * Request from setRequestPromise will be passed
215
     *
216
     * @param callable $callable
217
     */
218
    public function setAuthenticationCallback(callable $callable)
219
    {
220
        $this->authenticationCallable = $callable;
221
    }
222
223
    /**
224
     * @return callable|null
225
     */
226
    public function getAuthenticationCallback(): ?callable
227
    {
228
        return $this->authenticationCallable;
229
    }
230
}
231