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 ( 72f380...b3f20b )
by James
02:32
created

Server::getBeforeMethods()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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