| Total Complexity | 10 |
| Total Lines | 69 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 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 |
||
|
3 ignored issues
–
show
|
|||
| 28 | * @param mixed $value The value |
||
|
3 ignored issues
–
show
|
|||
| 29 | * @throws \UnexpectedValueException (description) |
||
|
1 ignored issue
–
show
|
|||
| 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 $name of the reference |
||
|
1 ignored issue
–
show
|
|||
| 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[(int) $index] = $value; |
||
| 61 | } |
||
| 62 | |||
| 63 | public function getComment(int $lineNumber = null) |
||
| 69 | } |
||
| 70 | |||
| 71 | public function setText(string $value):void |
||
| 72 | { |
||
| 73 | $this->value .= $value; |
||
| 74 | } |
||
| 75 | |||
| 76 | public function addTag(string $value):void |
||
| 79 | } |
||
| 80 | } |
||
| 81 |