Completed
Push — master ( c7418d...8b4244 )
by stéphane
04:44
created

API::hasDocStart()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace Dallgoot\Yaml;
4
5
use Dallgoot\Yaml\Yaml as Y;
6
7
/**
8
 * TODO
9
 *
10
 * @author  Stéphane Rebai <[email protected]>
11
 * @license Apache 2.0
12
 * @link    TODO : url to specific online doc
13
 */
0 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @package tag in class comment
Loading history...
14
class API
15
{
16
    /** @var null|bool */
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
17
    private $hasDocStart; // null = no docstart, true = docstart before document comments, false = docstart after document comments
0 ignored issues
show
Coding Style introduced by
Private member variable "hasDocStart" must be prefixed with an underscore
Loading history...
18
    private $_references = [];
19
    private $_comments   = [];
20
    // private $_documents  = [];
21
    private $_tags = [];
22
23
    public $type = Y::MAPPING;
24
    public $value = null;
25
26
    const UNKNOWN_REFERENCE = self::class.": no reference named '%s'";
27
    const UNAMED_REFERENCE  = self::class.": reference MUST have a name";
28
29
30
    /**
31
     * Adds a reference.
32
     *
33
     * @param string $name  The reference name
34
     * @param mixed  $value The reference value
35
     *
36
     * @throws \UnexpectedValueException  (description)
37
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
38
    public function addReference(string $name, $value)
39
    {
40
        if (empty($name)) {
41
            throw new \UnexpectedValueException(self::UNAMED_REFERENCE, 1);
42
        }
43
        $this->_references[(string) $name] = $value;
44
    }
45
46
    /**
47
     * Return the reference saved by $name
48
     *
49
     * @param string $name Name of the reference
50
     *
51
     * @return mixed Value of the reference
52
     * @throws \UnexpectedValueException    if there's no reference by that $name
53
     */
54
    public function &getReference($name)
55
    {
56
        if (array_key_exists($name, $this->_references)) {
57
            return $this->_references[$name];
58
        }
59
        throw new \UnexpectedValueException(sprintf(self::UNKNOWN_REFERENCE, $name), 1);
60
    }
61
62
    public function getAllReferences():array
0 ignored issues
show
Coding Style introduced by
Missing function doc comment
Loading history...
63
    {
64
        return $this->_references;
65
    }
66
67
    /**
68
     * Adds a comment.
69
     *
70
     * @param int    $lineNumber The line number at which thecomment should appear
71
     * @param string $value      The comment
72
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
73
    public function addComment(int $lineNumber, $value)
74
    {
75
        $this->_comments[$lineNumber] = $value;
76
    }
77
78
    /**
79
     * Gets the comment at $lineNumber
80
     *
81
     * @param int|null $lineNumber The line number
82
     *
83
     * @return string|array The comment at $lineNumber OR ALL comments.
84
     */
85
    public function getComment(int $lineNumber = null)
86
    {
87
        if (array_key_exists((int) $lineNumber, $this->_comments)) {
88
            return $this->_comments[$lineNumber];
89
        }
90
        return $this->_comments;
91
    }
92
93
    /**
94
     * Sets the text when the content is *only* a litteral
95
     *
96
     * @param string $value The value
97
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
98
    public function setText(string $value)
99
    {
100
        $this->value .= $value;
101
    }
102
103
    /**
104
     * TODO:  what to do with these tags ???
105
     * Adds a tag.
106
     *
107
     * @param string $value The value
108
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
109
    public function addTag(string $value)
110
    {
111
        $this->_tags[] = $value;
112
    }
113
114
    /**
115
     * Determines if it has YAML document start string => '---'.
116
     *
117
     * @return     boolean  True if has document start, False otherwise.
118
     */
119
    public function hasDocStart()
120
    {
121
        return is_bool($this->hasDocStart);
122
    }
123
124
    /**
125
     * Sets the document start.
126
     *
127
     * @param      null|bool  $value  The value : null = no docstart, true = docstart before document comments, false = docstart after document comments
128
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
129
    public function setDocStart($value)
130
    {
131
        $this->hasDocStart = $value;
132
    }
133
}
134