1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Dallgoot\Yaml\Nodes; |
4
|
|
|
|
5
|
|
|
use Dallgoot\Yaml; |
6
|
|
|
use Dallgoot\Yaml\Regex; |
7
|
|
|
use Dallgoot\Yaml\TagFactory; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* |
11
|
|
|
* @author Stéphane Rebai <[email protected]> |
12
|
|
|
* @license Apache 2.0 |
13
|
|
|
* @link https://github.com/dallgoot/yaml |
14
|
|
|
*/ |
15
|
|
|
class Directive extends NodeGeneric |
16
|
|
|
{ |
17
|
|
|
private const ERROR_BUILDING = "Error : can not build Directive"; |
18
|
|
|
private const WARNING_LOWER_VERSION = "The declared version '%f' is obsolete, there may be features that are deprecated and therefore not handled, minimum supported is :".Yaml::VERSION_SUPPORT; |
19
|
|
|
private const WARNING_HIGHER_VERSION = "The declared version '%f' is not yet supported, minimum supported is :".Yaml::VERSION_SUPPORT; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Builds a Directive : update YamlObject if applicable. |
23
|
|
|
* |
24
|
|
|
* @param object|array $parent The parent |
25
|
|
|
* |
26
|
|
|
* @throws \ParseError If Tag handle has been already set before. |
27
|
|
|
* |
28
|
|
|
* @return null |
29
|
|
|
*/ |
30
|
1 |
|
public function build(&$parent = null) |
31
|
|
|
{ |
32
|
1 |
|
if (preg_match(Regex::DIRECTIVE_TAG, $this->raw, $matches)) { |
33
|
|
|
try { |
34
|
|
|
$yamlObject = $this->getRoot()->getYamlObject(); |
35
|
|
|
//Try registering the handle in TagFactory |
36
|
|
|
TagFactory::registerHandle($matches['handle'], $matches['prefix']); |
37
|
|
|
$yamlObject->addTag($matches['handle'], $matches['prefix']); |
|
|
|
|
38
|
|
|
} catch (\Throwable $e) { |
39
|
|
|
throw new \ParseError(self::ERROR_BUILDING, 1, $e); |
40
|
|
|
} |
41
|
|
|
} |
42
|
1 |
|
if (preg_match(Regex::DIRECTIVE_VERSION, $this->raw, $matches)) { |
43
|
1 |
|
$contentVersion = (float) $matches['version']; |
44
|
1 |
|
if ($contentVersion > Yaml::VERSION_SUPPORT) { |
45
|
|
|
trigger_error(sprintf(self::WARNING_HIGHER_VERSION, $contentVersion), E_USER_WARNING); |
46
|
|
|
} |
47
|
1 |
|
if ($contentVersion < Yaml::VERSION_SUPPORT) { |
48
|
|
|
trigger_error(sprintf(self::WARNING_LOWER_VERSION, $contentVersion), E_USER_WARNING); |
49
|
|
|
} |
50
|
|
|
} |
51
|
1 |
|
return null; |
52
|
|
|
} |
53
|
|
|
|
54
|
1 |
|
public function add(NodeGeneric $child):NodeGeneric |
55
|
|
|
{ |
56
|
1 |
|
return $child; |
57
|
|
|
} |
58
|
|
|
} |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.