Passed
Branch master (f496ba)
by stéphane
02:11
created
Labels
Severity
1
<?php
2
namespace Dallgoot\Yaml;
3
4
use Dallgoot\Yaml\Types as T;
5
6
/**
7
 * the return Object representing a YAML file content
8
 *  consider dumping datetime as date strings according to a format provided by user or default
9
 */
10
class API
11
{
12
    private $_references = [];
13
    private $_comments   = [];
14
    // private $_documents  = [];
15
    private $tags = [];
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
28
     * @param   mixed                     $value  The value
29
     * @throws  \UnexpectedValueException  (description)
30
     */
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
41
     *  @param  string  nameof the reference
0 ignored issues
show
The type Dallgoot\Yaml\nameof was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
42
     *  @return mixed   the value of the reference
43
     *  @throws UnexpectedValueException    if there's no reference by that $name
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
54
    {
55
        return $this->_references;
56
    }
57
58
    public function addComment($index, $value):void
59
    {
60
        $this->_comments[$index] = $value;
61
    }
62
63
    public function getComment($lineNumber = null)
64
    {
65
        if (array_key_exists($lineNumber, $this->_comments)) {
66
            return $this->_comments[$lineNumber];
67
        }
68
        return $this->_comments;
69
    }
70
71
    public function setText($value):void
72
    {
73
        $this->value .= $value;
74
    }
75
76
    public function addTag($value):void
77
    {
78
        $this->tags[] = $value;
79
    }
80
}
81