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 ( c5d95d...eec97b )
by James
02:21
created

Server::setDetectionParameter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 1
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
     * The simple directive syntax when dumped.
101
     *
102
     * @var string
103
     */
104
    private $dumperSimpleDirective = '';
105
106
    /**
107
     * The starting block directive syntax when dumped.
108
     *
109
     * @var string
110
     */
111
    private $dumperStartDirective = '';
112
113
    /**
114
     * The ending block directive syntax when dumped.
115
     *
116
     * @var string
117
     */
118
    private $dumperEndDirective = '';
119
120
    /**
121
     * Sets the Checker instance.
122
     *
123
     * @param Checker $checker a Checker instance
124
     */
125 32
    public function setChecker(Checker $checker)
126
    {
127 32
        $this->checker = $checker;
128
129 32
        return $this;
130
    }
131
132
    /**
133
     * Confirms if the server instance has valid parameters.
134
     *
135
     * @return bool true if all parameters are initialized, false otherwise
136
     */
137 2
    public function isValid()
138
    {
139 2
        $valid = $this->prefix != '';
140 2
        $valid = $valid && $this->startMultiLine != '';
141 2
        $valid = $valid && $this->endMultiLine != '';
142 2
        $valid = $valid && $this->simpleDirective != '';
143
144 2
        return $valid;
145
    }
146
147
    /**
148
     * Getter for the prefix.
149
     *
150
     * @return string the filesystem path where the web server is installed
151
     */
152 4
    public function getPrefix()
153
    {
154 4
        return $this->prefix;
155
    }
156
157
    /**
158
     * Sets the prefix of a server instance.
159
     *
160
     *
161
     * @param string $prefix the filesystem path where the web server is installed
162
     *
163
     * @throws ServerException if the prefix is invalid
164
     */
165 11
    public function setPrefix($prefix)
166
    {
167 11
        if (!$this->checker->setString($prefix)->getString()) {
168 1
            throw ServerException::forInvalidPrefix($prefix, 'The path is expected to be a string. Got: %s');
169
        }
170
171 10
        if (!$this->checker->isValidAbsolutePath()) {
172 2
            throw ServerException::forInvalidPrefix(
173 2
                $prefix,
174
                'The path is expected to be absolute and an existing directory. Got: %s'
175 2
            );
176
        }
177
178 8
        $this->prefix = $prefix;
179
180 8
        return $this;
181
    }
182
183
    /**
184
     * Gets the regexp that will match the starting block directives.
185
     *
186
     * @return string the regexp that will match the starting block directives
187
     */
188 8
    public function getStartMultiLine()
189
    {
190 8
        return $this->startMultiLine;
191
    }
192
193
    /**
194
     * Sets the regexp that will match the starting block directives.
195
     *
196
     * @param string $startMultiLine the regexp that will match the starting block directives
197
     */
198 13
    public function setStartMultiLine($startMultiLine)
199
    {
200 13
        if ($this->isValidDirective(
201 13
            $startMultiLine,
202 13
            'The starting block directive matcher is expected to be a string. Got: %s',
203
            'The starting block directive matcher is expected to be a regexp '.
204
            'containing named subpatterns "key" and "value". Got: %s'
205 13
        )) {
206 8
            $this->startMultiLine = $startMultiLine;
207 8
        }
208
209 8
        return $this;
210
    }
211
212
    /**
213
     * Gets the regexp that will match the ending block directives.
214
     *
215
     * @return string the regexp that will match the ending block directives
216
     */
217 8
    public function getEndMultiLine()
218
    {
219 8
        return $this->endMultiLine;
220
    }
221
222
    /**
223
     * Sets the regexp that will match the ending block directives.
224
     *
225
     * @param string $endMultiLine the regexp that will match the ending block directives
226
     */
227 10
    public function setEndMultiLine($endMultiLine)
228
    {
229 10
        $this->endMultiLine = $this->setRegexDirective(
230 10
            $endMultiLine,
231 10
            'The ending block directive matcher is expected to be a string. Got: %s',
232
            'The ending block directive matcher is expected to be a regexp.'
233 10
        );
234
235 8
        return $this;
236
    }
237
238
    /**
239
     * Gets the regexp that will match the simple directives.
240
     *
241
     * @return string the regexp that will match the simple directives
242
     */
243 8
    public function getSimpleDirective()
244
    {
245 8
        return $this->simpleDirective;
246
    }
247
248
    /**
249
     * Sets the regexp that will match the simple directives.
250
     *
251
     * @param string $simpleDirective the regexp that will match the simple directives
252
     */
253 13
    public function setSimpleDirective($simpleDirective)
254
    {
255 13
        if ($this->isValidDirective(
256 13
            $simpleDirective,
257 13
            'The simple directive matcher is expected to be a string. Got: %s',
258
            'The simple directive matcher is expected to be a regexp '.
259
            'containing named subpatterns "key" and "value". Got: %s'
260 13
        )) {
261 8
            $this->simpleDirective = $simpleDirective;
262 8
        }
263
264 8
        return $this;
265
    }
266
267
    /**
268
     * Gets the regexp that will match the inclusion directives.
269
     *
270
     * @return string the regexp that will match the inclusion directives
271
     */
272 7
    public function getInclusionDirective()
273
    {
274 7
        return $this->inclusionDirective;
275
    }
276
277
    /**
278
     * Sets the regexp that will match the inclusion directives.
279
     *
280
     * @param string $inclusionDirective the regexp that will match the inclusion directives
281
     */
282 9
    public function setInclusionDirective($inclusionDirective)
283
    {
284 9
        $this->inclusionDirective = $this->setRegexDirective(
285 9
            $inclusionDirective,
286 9
            'The inclusion directive matcher is expected to be a string. Got: %s',
287
            'The inclusion directive matcher is expected to be a regexp.'
288 9
        );
289
290 7
        return $this;
291
    }
292
293
    /**
294
     * Sets the regular expression directive.
295
     *
296
     * @param string $directive the directive string
297
     * @param string $message1  message exception if the matcher is not a string
298
     * @param string $message2  message exception if the matcher is not a valid regex
299
     *
300
     * @throws ServerException if the directive matcher is invalid
301
     *
302
     * @return string the regular expression directive
303
     */
304 12 View Code Duplication
    private function setRegexDirective($directive, $message1, $message2)
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...
305
    {
306 12
        if (!$this->checker->setString($directive)->getString()) {
307 2
            throw ServerException::forInvalidMatcher(
308 2
                $directive,
309
                $message1
310 2
            );
311
        }
312
313 10
        if (!$this->checker->isValidRegex()) {
314 2
            throw ServerException::forInvalidMatcher(
315 2
                $directive,
316
                $message2
317 2
            );
318
        }
319
320 8
        return $directive;
321
    }
322
323
    /**
324
     * Confirms if a directive matcher is a valid regex.
325
     *
326
     * @param string $directive the directive matcher to check
327
     * @param string $message1  message exception if the matcher is not a string
328
     * @param string $message2  message exception if the matcher is not a valid regex
329
     *
330
     * @throws ServerException if the directive matcher is invalid
331
     *
332
     * @return bool true if the directive matcher is valid
333
     */
334 19 View Code Duplication
    private function isValidDirective($directive, $message1, $message2)
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...
335
    {
336 19
        if (!$this->checker->setString($directive)->getString()) {
337 2
            throw ServerException::forInvalidMatcher(
338 2
                $directive,
339
                $message1
340 2
            );
341
        }
342
343 17
        if (!$this->checker->hasKeyAndValueSubPattern()) {
344 8
            throw ServerException::forInvalidMatcher(
345 8
                $directive,
346
                $message2
347 8
            );
348
        }
349
350 9
        return true;
351
    }
352
353
    /**
354
     * Gets the list of binaries that can be run to analyze.
355
     *
356
     * @return array the list of binaries that can be run
357
     */
358 1
    public function getBinaries()
359
    {
360 1
        return $this->binaries;
361
    }
362
363
    /**
364
     * Sets the list of binaries that can be run to analyze.
365
     *
366
     * @param array $binaries list of controlers
367
     */
368 8
    public function setBinaries(array $binaries)
369
    {
370 8
        $this->binaries = $binaries;
371
372 8
        return $this;
373
    }
374
375
    /**
376
     * Gets the parameter string to use to detect version and config file.
377
     *
378
     * @return string parameter string
379
     */
380 1
    public function getDetectionParameter()
381
    {
382 1
        return $this->detectionParameter;
383
    }
384
385
    /**
386
     * Sets the parameter string to use to detect version and config file.
387
     *
388
     * @param string $parameter parameter string
389
     */
390 8
    public function setDetectionParameter($parameter = '')
391
    {
392 8
        $this->detectionParameter = $parameter;
393
394 8
        return $this;
395
    }
396
397
    /**
398
     * Gets the ordered list of methods to apply before the config file turns into an array.
399
     *
400
     * @return array the ordered list of methods to apply before convertion
401
     */
402 14
    public function getBeforeMethods()
403
    {
404 14
        return $this->beforeMethods;
405
    }
406
407
    /**
408
     * Sets the ordered list of methods to apply before the config file turns into an array.
409
     *
410
     * @param array $methods the ordered list of methods to apply before convertion
411
     */
412 13
    public function setBeforeMethods(array $methods)
413
    {
414 13
        $this->beforeMethods = $methods;
415
416 13
        return $this;
417
    }
418
419
    /**
420
     * Gets the ordered list of methods to apply after the config file has turned into an array.
421
     *
422
     * @return array the ordered list of methods to apply after convertion
423
     */
424 14
    public function getAfterMethods()
425
    {
426 14
        return $this->afterMethods;
427
    }
428
429
    /**
430
     * Sets the ordered list of methods to apply after the config file has turned into an array.
431
     *
432
     * @param array $methods the ordered list of methods to apply after convertion
433
     */
434 13
    public function setAfterMethods(array $methods)
435
    {
436 13
        $this->afterMethods = $methods;
437
438 13
        return $this;
439
    }
440
441
    /**
442
     * Gets the simple directive syntax when dumped.
443
     *
444
     * @return string the simple directive syntax when dumped
445
     */
446 1
    public function getDumperSimpleDirective()
447
    {
448 1
        return $this->dumperSimpleDirective;
449
    }
450
451
    /**
452
     * Gets the starting block directive syntax when dumped.
453
     *
454
     * @return string the starting block directive syntax when dumped
455
     */
456 1
    public function getDumperStartDirective()
457
    {
458 1
        return $this->dumperStartDirective;
459
    }
460
461
    /**
462
     * Gets the ending block directive syntax when dumped.
463
     *
464
     * @return string the ending block directive syntax when dumped
465
     */
466 1
    public function getDumperEndDirective()
467
    {
468 1
        return $this->dumperEndDirective;
469
    }
470
471
    /**
472
     * Sets the simple directive syntax when dumped.
473
     *
474
     * @param string $simpleDirective the simple directive syntax when dumped
475
     */
476 8
    public function setDumperSimpleDirective($simpleDirective)
477
    {
478 8
        $this->dumperSimpleDirective = $simpleDirective;
479
480 8
        return $this;
481
    }
482
483
    /**
484
     * Sets the starting block directive syntax when dumped.
485
     *
486
     * @param string $startMultiLine the starting block directive syntax when dumped
487
     */
488 8
    public function setDumperStartDirective($startMultiLine)
489
    {
490 8
        $this->dumperStartDirective = $startMultiLine;
491
492 8
        return $this;
493
    }
494
495
    /**
496
     * Sets the ending block directive syntax when dumped.
497
     *
498
     * @param string $endMultiLine the ending block directive syntax when dumped
499
     */
500 8
    public function setDumperEndDirective($endMultiLine)
501
    {
502 8
        $this->dumperEndDirective = $endMultiLine;
503
504 8
        return $this;
505
    }
506
}
507