Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
71.43% |
15 / 21 |
|
77.78% |
7 / 9 |
CRAP | |
0.00% |
0 / 1 |
| SimpleMetadataValue | |
71.43% |
15 / 21 |
|
77.78% |
7 / 9 |
15.36 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| setResourceIdentifier | |
42.86% |
3 / 7 |
|
0.00% |
0 / 1 |
4.68 | |||
| getResourceIdentifier | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setPath | |
50.00% |
2 / 4 |
|
0.00% |
0 / 1 |
2.50 | |||
| getPath | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setValue | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getValue | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setLanguage | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getLanguage | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; under version 2 |
| 7 | * of the License (non-upgradable). |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * |
| 18 | * Copyright (c) 2014 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | namespace oat\taoQtiItem\model\qti\metadata\simple; |
| 23 | |
| 24 | use oat\taoQtiItem\model\qti\metadata\MetadataValue; |
| 25 | use InvalidArgumentException; |
| 26 | |
| 27 | /** |
| 28 | * A Basic implementation of the MetadataValue interface. |
| 29 | * |
| 30 | * @author Jérôme Bogaerts <jerome@taotesting.com> |
| 31 | */ |
| 32 | class SimpleMetadataValue implements MetadataValue |
| 33 | { |
| 34 | /** |
| 35 | * The Resource Identifier the MetadataValue belongs to. |
| 36 | * |
| 37 | * @var string |
| 38 | */ |
| 39 | private $resourceIdentifier; |
| 40 | |
| 41 | /** |
| 42 | * The language of the MetadatValue. |
| 43 | * |
| 44 | * @var string |
| 45 | */ |
| 46 | private $language; |
| 47 | |
| 48 | /** |
| 49 | * The Path of the MetadataValue. |
| 50 | * |
| 51 | * @var array |
| 52 | */ |
| 53 | private $path; |
| 54 | |
| 55 | /** |
| 56 | * The intrinsic value of the MetadataValue. |
| 57 | * |
| 58 | * @var string |
| 59 | */ |
| 60 | private $value; |
| 61 | |
| 62 | /** |
| 63 | * Create a new SimpleMetadataValue object. |
| 64 | * |
| 65 | * @param string $resourceIdentifier The Identifier of the resource the MetadataValue describes. |
| 66 | * @param array $path The descriptive path of the metadata. |
| 67 | * @param string $value The intrinsic value of the MetadataValue. |
| 68 | * @param string $language A string. If no specific language, an empty string is accepted. |
| 69 | * @throws InvalidArgumentException If one of the argument contains an invalid value. |
| 70 | */ |
| 71 | public function __construct($resourceIdentifier, $path, $value, $language = '') |
| 72 | { |
| 73 | $this->setResourceIdentifier($resourceIdentifier); |
| 74 | $this->setPath($path); |
| 75 | $this->setValue($value); |
| 76 | $this->setLanguage($language); |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Set the identifier of the resource the MetadataValue describes. |
| 81 | * |
| 82 | * @param string $resourceIdentifier An identifier. |
| 83 | * @throws InvalidArgumentException If $resourceIdentifier is not a string or an empty string. |
| 84 | */ |
| 85 | public function setResourceIdentifier($resourceIdentifier) |
| 86 | { |
| 87 | if (is_string($resourceIdentifier) === false) { |
| 88 | $msg = "The resourceIdentifier argument must be a string."; |
| 89 | throw new InvalidArgumentException($msg); |
| 90 | } elseif ($resourceIdentifier === '') { |
| 91 | $msg = "The resourceIdentifier argument must be a non-empty string."; |
| 92 | throw new InvalidArgumentException($msg); |
| 93 | } else { |
| 94 | $this->resourceIdentifier = $resourceIdentifier; |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * @see \oat\taoQtiItem\model\qti\metadata\MetadataValue::getResourceIdentifier() |
| 100 | */ |
| 101 | public function getResourceIdentifier() |
| 102 | { |
| 103 | return $this->resourceIdentifier; |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * Set the descriptive path of the MetadataValue. |
| 108 | * |
| 109 | * @param array $path An array of Path Components. |
| 110 | * @throws InvalidArgumentException If $path is an empty array. |
| 111 | */ |
| 112 | public function setPath(array $path) |
| 113 | { |
| 114 | if (count($path) === 0) { |
| 115 | $msg = "The path argument must be a non-empty array."; |
| 116 | throw new InvalidArgumentException($msg); |
| 117 | } else { |
| 118 | $this->path = $path; |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * @see \oat\taoQtiItem\model\qti\metadata\MetadataValue::getPath() |
| 124 | */ |
| 125 | public function getPath() |
| 126 | { |
| 127 | return $this->path; |
| 128 | } |
| 129 | |
| 130 | /** |
| 131 | * Set the intrinsic value of the MetadataValue. |
| 132 | * |
| 133 | * @param string $value An intrinsic value. |
| 134 | */ |
| 135 | public function setValue($value) |
| 136 | { |
| 137 | $this->value = $value; |
| 138 | } |
| 139 | |
| 140 | /** |
| 141 | * @see \oat\taoQtiItem\model\qti\metadata\MetadataValue::getValue() |
| 142 | */ |
| 143 | public function getValue() |
| 144 | { |
| 145 | return $this->value; |
| 146 | } |
| 147 | |
| 148 | /** |
| 149 | * Set the language of the MetadataValue. If the intrinsic value of |
| 150 | * the MetadataValue has no specific language, $language is an empty string. |
| 151 | * |
| 152 | * @param string $language A language or an empty string. |
| 153 | */ |
| 154 | public function setLanguage($language) |
| 155 | { |
| 156 | $this->language = $language; |
| 157 | } |
| 158 | |
| 159 | /** |
| 160 | * @see \oat\taoQtiItem\model\qti\metadata\MetadataValue::getLanguage() |
| 161 | */ |
| 162 | public function getLanguage() |
| 163 | { |
| 164 | return $this->language; |
| 165 | } |
| 166 | } |