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\Directive; |
13
|
|
|
|
14
|
|
|
use WebHelper\Parser\Server\ServerInterface; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Describes a simple directive instance. |
18
|
|
|
* |
19
|
|
|
* a SimpleDirective is a simple key/value information. |
20
|
|
|
* |
21
|
|
|
* @author James <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
class SimpleDirective extends Directive implements DirectiveInterface |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* Confirms if the directive contains a specified directive. |
27
|
|
|
* |
28
|
|
|
* @param string $name the directive for which to check existence |
29
|
|
|
* |
30
|
|
|
* @return bool true if the sub-directive exists, false otherwise |
31
|
|
|
*/ |
32
|
1 |
|
public function hasDirective($name) |
33
|
|
|
{ |
34
|
1 |
|
return false; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Confirms if the directive is simple. |
39
|
|
|
* |
40
|
|
|
* Simple directive cannot have sub directive |
41
|
|
|
* |
42
|
|
|
* @return bool true if the directive is simple, false otherwise |
43
|
|
|
*/ |
44
|
1 |
|
public function isSimple() |
45
|
|
|
{ |
46
|
1 |
|
return true; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Dumps the directive respecting a server syntax. |
51
|
|
|
* |
52
|
|
|
* @param ServerInterface $server a server instance |
53
|
|
|
* @param int $spaces the indentation spaces |
54
|
|
|
* |
55
|
|
|
* @return string the dumped directive |
56
|
|
|
*/ |
57
|
1 |
View Code Duplication |
public function dump(ServerInterface $server, $spaces = 0) |
|
|
|
|
58
|
|
|
{ |
59
|
1 |
|
$value = $this->getValue() ? ' '.$this->getValue() : ''; |
60
|
|
|
|
61
|
1 |
|
return str_repeat(' ', $spaces).sprintf( |
62
|
1 |
|
$server->getDumperSimpleDirective(), |
63
|
1 |
|
$this->getName(), |
64
|
|
|
$value |
65
|
1 |
|
).PHP_EOL; |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
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.