Completed
Push — master ( 86484b...f97b0a )
by stéphane
05:27
created

Tagged   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 8
dl 0
loc 24
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 2
1
<?php
2
namespace Dallgoot\Yaml;
3
4
use \ReflectionMethod as RM;
5
6
/**
7
 * The Yaml\Tag class is an object type that encapsulates current
8
 * value which is tagged but no methods have been declared
9
 * by user (or standard) to transform it.
10
 * To register a method (Closure) for a specfici tag see Yaml\TagFactory
11
 *
12
 * @author  Stéphane Rebai <[email protected]>
13
 * @license Apache 2.0
14
 * @link    https://github.com/dallgoot/yaml
15
 * @see     TagFactory
16
 */
17
final class Tagged
18
{
19
    /** @var string */
20
    public $tagName;
21
    /** @var mixed */
22
    public $value;
23
24
    private const NO_NAME = '%s Error: a tag MUST have a name';
25
26
    /**
27
     * Tag constructor.
28
     *
29
     * @param string $tagName the name of the tag like '!!str'
30
     * @param mixed  $raw     any PHP variable type
31
     *
32
     * @throws \Exception if $tagName is an invalid string or absent
33
     */
34
    public function __construct(string $tagName, $value)
35
    {
36
        if (empty($tagName)) {
37
            throw new \Exception(sprintf(self::NO_NAME, __METHOD__));
38
        }
39
        $this->tagName = $tagName;
40
        $this->value   = $value;
41
    }
42
43
    /**
44
     * Should verify if the tag is correct
45
     *
46
     * @param string $providedName The provided name
47
     * @todo  is this required ???
48
     */
49
    // private function checkNameValidity(string $providedName)
50
    // {
51
        /* TODO  implement and throw Exception if invalid (setName method ???)
52
         *The suffix must not contain any “!” character. This would cause the tag shorthand to be interpreted as having a named tag handle. In addition, the suffix must not contain the “[”, “]”, “{”, “}” and “,” characters. These characters would cause ambiguity with flow collection structures. If the suffix needs to specify any of the above restricted characters, they must be escaped using the “%” character. This behavior is consistent with the URI character escaping rules (specifically, section 2.3 of RFC2396).
53
54
         regex (([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?
55
        */
56
    // }
57
}