Passed
Branch master (f496ba)
by stéphane
02:11
created

API::getComment()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
namespace Dallgoot\Yaml;
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
4
use Dallgoot\Yaml\Types as T;
5
6
/**
7
 * the return Object representing a YAML file content
0 ignored issues
show
Coding Style introduced by
Doc comment short description must start with a capital letter
Loading history...
8
 *  consider dumping datetime as date strings according to a format provided by user or default
9
 */
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...
Coding Style introduced by
Missing @author tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
10
class API
11
{
12
    private $_references = [];
13
    private $_comments   = [];
14
    // private $_documents  = [];
15
    private $tags = [];
0 ignored issues
show
Coding Style introduced by
Private member variable "tags" must be prefixed with an underscore
Loading history...
16
17
    public $type = T::MAPPING;
18
    public $value = null;
19
20
    const UNKNOWN_REFERENCE = self::class.": no reference named '%s'";
21
    const UNAMED_REFERENCE  = self::class.": reference MUST have a name";
22
23
24
    /**
25
     * Adds a reference.
26
     *
27
     * @param   string                    $name   The name
3 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 20 found
Loading history...
Coding Style introduced by
Expected 2 spaces after parameter name; 3 found
Loading history...
Coding Style introduced by
Tag value indented incorrectly; expected 2 spaces but found 3
Loading history...
28
     * @param   mixed                     $value  The value
3 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter type; 21 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 2 found
Loading history...
Coding Style introduced by
Tag value indented incorrectly; expected 2 spaces but found 3
Loading history...
29
     * @throws  \UnexpectedValueException  (description)
1 ignored issue
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
Coding Style introduced by
Tag value indented incorrectly; expected 1 spaces but found 2
Loading history...
30
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
31
    public function addReference($name, $value):void
32
    {
33
        if (empty($name)) {
34
            throw new \UnexpectedValueException(self::UNAMED_REFERENCE, 1);
35
        }
36
        $this->_references[$name] = $value;
37
    }
38
39
    /**
40
     *  return the reference saved by $name
0 ignored issues
show
Coding Style introduced by
Doc comment short description must start with a capital letter
Loading history...
41
     *  @param  string  $name of the reference
1 ignored issue
show
Coding Style introduced by
There must be exactly one blank line before the tags in a doc comment
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
42
     *  @return mixed   the value of the reference
0 ignored issues
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
43
     *  @throws UnexpectedValueException    if there's no reference by that $name
0 ignored issues
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
44
     */
45
    public function &getReference($name)
46
    {
47
        if (array_key_exists($name, $this->_references)) {
48
            return $this->_references[$name];
49
        }
50
        throw new \UnexpectedValueException(sprintf(self::UNKNOWN_REFERENCE, $name), 1);
51
    }
52
53
    public function getAllReferences():array
0 ignored issues
show
Coding Style introduced by
Missing function doc comment
Loading history...
54
    {
55
        return $this->_references;
56
    }
57
58
    public function addComment($index, $value):void
0 ignored issues
show
Coding Style introduced by
Missing function doc comment
Loading history...
59
    {
60
        $this->_comments[(int) $index] = $value;
61
    }
62
63
    public function getComment(int $lineNumber = null)
0 ignored issues
show
Coding Style introduced by
Missing function doc comment
Loading history...
64
    {
65
        if (array_key_exists((int) $lineNumber, $this->_comments)) {
66
            return $this->_comments[$lineNumber];
67
        }
68
        return $this->_comments;
69
    }
70
71
    public function setText(string $value):void
0 ignored issues
show
Coding Style introduced by
Missing function doc comment
Loading history...
72
    {
73
        $this->value .= $value;
74
    }
75
76
    public function addTag(string $value):void
0 ignored issues
show
Coding Style introduced by
Missing function doc comment
Loading history...
77
    {
78
        $this->tags[] = $value;
79
    }
80
}
81