|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Dallgoot\Yaml\Nodes; |
|
4
|
|
|
|
|
5
|
|
|
use Dallgoot\Yaml\NodeList; |
|
6
|
|
|
use Dallgoot\Yaml\TagFactory; |
|
7
|
|
|
use Dallgoot\Yaml\Tagged; |
|
8
|
|
|
use Dallgoot\Yaml\Regex; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* |
|
12
|
|
|
* @author Stéphane Rebai <[email protected]> |
|
13
|
|
|
* @license Apache 2.0 |
|
14
|
|
|
* @link https://github.com/dallgoot/yaml |
|
15
|
|
|
* @todo handle tags like <tag:clarkevans.com,2002:invoice> |
|
16
|
|
|
*/ |
|
17
|
|
|
class Tag extends Actions |
|
18
|
|
|
{ |
|
19
|
|
|
|
|
20
|
1 |
|
public function isAwaitingChild(NodeGeneric $node):bool |
|
21
|
|
|
{ |
|
22
|
1 |
|
return is_null($this->value); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
1 |
|
public function getTargetOnEqualIndent(NodeGeneric &$node):NodeGeneric |
|
26
|
|
|
{ |
|
27
|
1 |
|
if (is_null($this->value)) { |
|
28
|
1 |
|
return $this; |
|
29
|
|
|
} else { |
|
30
|
1 |
|
return $this->getParent(); |
|
31
|
|
|
} |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Builds a tag and its value (also built) and encapsulates them in a Tag object. |
|
36
|
|
|
* |
|
37
|
|
|
* @param array|object|null $parent The parent |
|
38
|
|
|
* |
|
39
|
|
|
* @return Tagged|mixed The tag object of class Dallgoot\Yaml\Tagged. |
|
40
|
|
|
*/ |
|
41
|
1 |
|
public function build(&$parent = null) |
|
42
|
|
|
{ |
|
43
|
1 |
|
if (is_null($this->value) && $this->getParent() instanceof Root) { |
|
44
|
1 |
|
if (!preg_match(Regex::TAG_PARTS, $this->tag, $matches)) { |
|
45
|
|
|
throw new \UnexpectedValueException("Tag '$this->tag' is invalid", 1); |
|
46
|
|
|
} |
|
47
|
1 |
|
$handle = $matches['handle']; |
|
48
|
1 |
|
$tagname = $matches['tagname']; |
|
49
|
1 |
|
$this->getRoot()->getYamlObject()->addTag($handle, $tagname); |
|
50
|
1 |
|
return; |
|
51
|
|
|
} |
|
52
|
1 |
|
$value = $this->value; |
|
53
|
1 |
|
if (is_null($parent) && $value->isOneOf('Item', 'Key')) { |
|
|
|
|
|
|
54
|
|
|
$value = new NodeList(/** @scrutinizer ignore-type */ $value); |
|
55
|
|
|
} |
|
56
|
1 |
|
if ($value instanceof Literals) { |
|
57
|
|
|
$value = $value->value; |
|
58
|
|
|
} |
|
59
|
1 |
|
$transformed = TagFactory::transform((string) $this->tag, $value); |
|
60
|
1 |
|
if ($transformed instanceof NodeGeneric || $transformed instanceof NodeList) { |
|
61
|
|
|
return $transformed->build($parent); |
|
62
|
|
|
} |
|
63
|
1 |
|
return $transformed; |
|
64
|
|
|
} |
|
65
|
|
|
} |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.