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.
Completed
Push — master ( e0baf9...7f2ebd )
by James
03:10
created

Server::isValid()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 6
cts 6
cp 1
rs 9.2
c 0
b 0
f 0
cc 4
eloc 6
nc 8
nop 0
crap 4
1
<?php
2
3
/**
4
 * This file is part of WebHelper Parser.
5
 *
6
 * (c) James <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace WebHelper\Parser\Server;
13
14
use WebHelper\Parser\Parser\Checker;
15
16
/**
17
 * A web server instance.
18
 *
19
 * @author James <[email protected]>
20
 */
21
class Server implements ServerInterface
22
{
23
    /**
24
     * a Checker instance.
25
     *
26
     * @var \WebHelper\Parser\Parser\Checker
27
     */
28
    private $checker;
29
30
    /**
31
     * The filesystem path where the web server is installed.
32
     *
33
     * It has to be an absolute path.
34
     *
35
     * Apache httpd server does not accept a relative prefix path at compilation.
36
     * Nginx does, but this is a very risky practice...
37
     * So relative prefix path in nginx configuration will not be considered
38
     *
39
     * @var string
40
     */
41
    private $prefix = '';
42
43
    /**
44
     * The string to match as a starting multi-line directive.
45
     *
46
     * @var string
47
     */
48
    private $startMultiLine = '';
49
50
    /**
51
     * The string to match as an ending multi-line directive.
52
     *
53
     * @var string
54
     */
55
    private $endMultiLine = '';
56
57
    /**
58
     * The string to match a simple directive.
59
     *
60
     * @var string
61
     */
62
    private $simpleDirective = '';
63
64
    /**
65
     * The string to match an inclusion directive.
66
     *
67
     * @var string
68
     */
69
    private $inclusionDirective = '';
70
71
    /**
72
     * binaries that can be used to control the webserver.
73
     *
74
     * @var array
75
     */
76
    private $binaries = [];
77
78
    /**
79
     * the parameter string to use to detect version and config file.
80
     *
81
     * @var string
82
     */
83
    private $detectionParameter = '';
84
85
    /**
86
     * The ordered list of methods to apply before convertion.
87
     *
88
     * @var array
89
     */
90
    private $beforeMethods = [];
91
92
    /**
93
     * The ordered list of methods to apply after convertion.
94
     *
95
     * @var array
96
     */
97
    private $afterMethods = [];
98
99
    /**
100
     * Sets the Checker instance.
101
     *
102
     * @param Checker $checker a Checker instance
103
     */
104 32
    public function setChecker(Checker $checker)
105
    {
106 32
        $this->checker = $checker;
107
108 32
        return $this;
109
    }
110
111
    /**
112
     * Confirms if the server instance has valid parameters.
113
     *
114
     * @return bool true if all parameters are initialized, false otherwise
115
     */
116 2
    public function isValid()
117
    {
118 2
        $valid = $this->prefix != '';
119 2
        $valid = $valid && $this->startMultiLine != '';
120 2
        $valid = $valid && $this->endMultiLine != '';
121 2
        $valid = $valid && $this->simpleDirective != '';
122
123 2
        return $valid;
124
    }
125
126
    /**
127
     * Getter for the prefix.
128
     *
129
     * @return string the filesystem path where the web server is installed
130
     */
131 9
    public function getPrefix()
132
    {
133 9
        return $this->prefix;
134
    }
135
136
    /**
137
     * Sets the prefix of a server instance.
138
     *
139
     * @throws ServerException if the prefix is invalid
140
     *
141
     * @param string $prefix the filesystem path where the web server is installed
142
     */
143 11
    public function setPrefix($prefix)
144
    {
145 11
        if (!$this->checker->setString($prefix)->getString()) {
146 1
            throw ServerException::forInvalidPrefix($prefix, 'The path is expected to be a string. Got: %s');
147
        }
148
149 10
        if (!$this->checker->isValidAbsolutePath()) {
150 2
            throw ServerException::forInvalidPrefix(
151 2
                $prefix,
152
                'The path is expected to be absolute and an existing directory. Got: %s'
153 2
            );
154
        }
155
156 8
        $this->prefix = $prefix;
157
158 8
        return $this;
159
    }
160
161
    /**
162
     * Gets the regexp that will match the starting block directives.
163
     *
164
     * @return string the regexp that will match the starting block directives
165
     */
166 8
    public function getStartMultiLine()
167
    {
168 8
        return $this->startMultiLine;
169
    }
170
171
    /**
172
     * Sets the regexp that will match the starting block directives.
173
     *
174
     * @param string $startMultiLine the regexp that will match the starting block directives
175
     */
176 13
    public function setStartMultiLine($startMultiLine)
177
    {
178 13
        if ($this->isValidDirective(
179 13
            $startMultiLine,
180 13
            'The starting block directive matcher is expected to be a string. Got: %s',
181
            'The starting block directive matcher is expected to be a regexp '.
182
            'containing named subpatterns "key" and "value". Got: %s'
183 13
        )) {
184 8
            $this->startMultiLine = $startMultiLine;
185 8
        }
186
187 8
        return $this;
188
    }
189
190
    /**
191
     * Gets the regexp that will match the ending block directives.
192
     *
193
     * @return string the regexp that will match the ending block directives
194
     */
195 8
    public function getEndMultiLine()
196
    {
197 8
        return $this->endMultiLine;
198
    }
199
200
    /**
201
     * Sets the regexp that will match the ending block directives.
202
     *
203
     * @param string $endMultiLine the regexp that will match the ending block directives
204
     */
205 10 View Code Duplication
    public function setEndMultiLine($endMultiLine)
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...
206
    {
207 10
        if (!$this->checker->setString($endMultiLine)->getString()) {
208 1
            throw ServerException::forInvalidMatcher(
209 1
                $endMultiLine,
210
                'The ending block directive matcher is expected to be a string. Got: %s'
211 1
            );
212
        }
213
214 9
        if (!$this->checker->isValidRegex()) {
215 1
            throw ServerException::forInvalidMatcher(
216 1
                $endMultiLine,
217
                'The ending block directive matcher is expected to be a regexp.'
218 1
            );
219
        }
220
221 8
        $this->endMultiLine = $endMultiLine;
222
223 8
        return $this;
224
    }
225
226
    /**
227
     * Gets the regexp that will match the simple directives.
228
     *
229
     * @return string the regexp that will match the simple directives
230
     */
231 8
    public function getSimpleDirective()
232
    {
233 8
        return $this->simpleDirective;
234
    }
235
236
    /**
237
     * Sets the regexp that will match the simple directives.
238
     *
239
     * @param string $simpleDirective the regexp that will match the simple directives
240
     */
241 13
    public function setSimpleDirective($simpleDirective)
242
    {
243 13
        if ($this->isValidDirective(
244 13
            $simpleDirective,
245 13
            'The simple directive matcher is expected to be a string. Got: %s',
246
            'The simple directive matcher is expected to be a regexp '.
247
            'containing named subpatterns "key" and "value". Got: %s'
248 13
        )) {
249 8
            $this->simpleDirective = $simpleDirective;
250 8
        }
251
252 8
        return $this;
253
    }
254
255
    /**
256
     * Gets the regexp that will match the inclusion directives.
257
     *
258
     * @return string the regexp that will match the inclusion directives
259
     */
260 7
    public function getInclusionDirective()
261
    {
262 7
        return $this->inclusionDirective;
263
    }
264
265
    /**
266
     * Sets the regexp that will match the inclusion directives.
267
     *
268
     * @param string $simpleDirective the regexp that will match the inclusion directives
0 ignored issues
show
Bug introduced by
There is no parameter named $simpleDirective. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

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

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

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

Loading history...
269
     */
270 9 View Code Duplication
    public function setInclusionDirective($inclusionDirective)
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...
271
    {
272 9
        if (!$this->checker->setString($inclusionDirective)->getString()) {
273 1
            throw ServerException::forInvalidMatcher(
274 1
                $inclusionDirective,
275
                'The inclusion directive matcher is expected to be a string. Got: %s'
276 1
            );
277
        }
278
279 8
        if (!$this->checker->isValidRegex()) {
280 1
            throw ServerException::forInvalidMatcher(
281 1
                $inclusionDirective,
282
                'The inclusion directive matcher is expected to be a regexp.'
283 1
            );
284
        }
285
286 7
        $this->inclusionDirective = $inclusionDirective;
287
288 7
        return $this;
289
    }
290
291
    /**
292
     * Confirms if a directive matcher is a valid regex.
293
     *
294
     * @param string $directive the directive matcher to check
295
     * @param string $message1  message exception if the matcher is not a string
296
     * @param string $message2  message exception if the matcher is not a valid regex
297
     *
298
     * @throws ServerException if the directive matcher is invalid
299
     *
300
     * @return bool true if the directive matcher is valid
301
     */
302 19
    private function isValidDirective($directive, $message1, $message2)
303
    {
304 19
        if (!$this->checker->setString($directive)->getString()) {
305 2
            throw ServerException::forInvalidMatcher(
306 2
                $directive,
307
                $message1
308 2
            );
309
        }
310
311 17
        if (!$this->checker->hasKeyAndValueSubPattern()) {
312 8
            throw ServerException::forInvalidMatcher(
313 8
                $directive,
314
                $message2
315 8
            );
316
        }
317
318 9
        return true;
319
    }
320
321
    /**
322
     * Gets the list of binaries that can be run to analyze.
323
     *
324
     * @return array the list of binaries that can be run
325
     */
326 1
    public function getBinaries()
327
    {
328 1
        return $this->binaries;
329
    }
330
331
    /**
332
     * Sets the list of binaries that can be run to analyze.
333
     *
334
     * @param array $binaries list of controlers
335
     */
336 8
    public function setBinaries(array $binaries)
337
    {
338 8
        $this->binaries = $binaries;
339
340 8
        return $this;
341
    }
342
343
    /**
344
     * Gets the parameter string to use to detect version and config file.
345
     *
346
     * @return string parameter string
347
     */
348 1
    public function getDetectionParameter()
349
    {
350 1
        return $this->detectionParameter;
351
    }
352
353
    /**
354
     * Sets the parameter string to use to detect version and config file.
355
     *
356
     * @param string $parameter parameter string
357
     */
358 8
    public function setDetectionParameter($parameter = '')
359
    {
360 8
        $this->detectionParameter = $parameter;
361
362 8
        return $this;
363
    }
364
365
    /**
366
     * Gets the ordered list of methods to apply before the config file turns into an array.
367
     *
368
     * @return array the ordered list of methods to apply before convertion
369
     */
370 11
    public function getBeforeMethods()
371
    {
372 11
        return $this->beforeMethods;
373
    }
374
375
    /**
376
     * Sets the ordered list of methods to apply before the config file turns into an array.
377
     *
378
     * @param array $methods the ordered list of methods to apply before convertion
379
     */
380 13
    public function setBeforeMethods(array $methods)
381
    {
382 13
        $this->beforeMethods = $methods;
383
384 13
        return $this;
385
    }
386
387
    /**
388
     * Gets the ordered list of methods to apply after the config file has turned into an array.
389
     *
390
     * @return array the ordered list of methods to apply after convertion
391
     */
392 11
    public function getAfterMethods()
393
    {
394 11
        return $this->afterMethods;
395
    }
396
397
    /**
398
     * Sets the ordered list of methods to apply after the config file has turned into an array.
399
     *
400
     * @param array $methods the ordered list of methods to apply after convertion
401
     */
402 13
    public function setAfterMethods(array $methods)
403
    {
404 13
        $this->afterMethods = $methods;
405
406 13
        return $this;
407
    }
408
}
409