php-xapi /
model
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | /* |
||
| 4 | * This file is part of the xAPI package. |
||
| 5 | * |
||
| 6 | * (c) Christian Flothmann <[email protected]> |
||
| 7 | * |
||
| 8 | * For the full copyright and license information, please view the LICENSE |
||
| 9 | * file that was distributed with this source code. |
||
| 10 | */ |
||
| 11 | |||
| 12 | namespace Xabbuh\XApi\Model; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * Definition of an {@link Activity}. |
||
| 16 | * |
||
| 17 | * A number of derived classes exists each of them covering a specialized |
||
| 18 | * type of user interaction: |
||
| 19 | * |
||
| 20 | * <ul> |
||
| 21 | * <li>ChoiceInteractionDefinition</li> |
||
| 22 | * <li>FillInteractionDefinition</li> |
||
| 23 | * <li>LikertInteractionDefinition</li> |
||
| 24 | * <li>LongFillInInteractionDefinition</li> |
||
| 25 | * <li>MatchingInteractionDefinition</li> |
||
| 26 | * <li>NumericInteractionDefinition</li> |
||
| 27 | * <li>PerformanceInteractionDefinition</li> |
||
| 28 | * <li>OtherInteractionDefinition</li> |
||
| 29 | * <li>SequencingInteractionDefinition</li> |
||
| 30 | * <li>TrueFalseInteractionDefinition</li> |
||
| 31 | * </ul> |
||
| 32 | * |
||
| 33 | * @author Christian Flothmann <[email protected]> |
||
| 34 | */ |
||
| 35 | class Definition |
||
| 36 | { |
||
| 37 | private $name; |
||
| 38 | private $description; |
||
| 39 | private $type; |
||
| 40 | private $moreInfo; |
||
| 41 | private $extensions; |
||
| 42 | |||
| 43 | public function __construct(LanguageMap $name = null, LanguageMap $description = null, IRI $type = null, IRL $moreInfo = null, Extensions $extensions = null) |
||
| 44 | { |
||
| 45 | $this->name = $name; |
||
| 46 | $this->description = $description; |
||
| 47 | $this->type = $type; |
||
| 48 | $this->moreInfo = $moreInfo; |
||
| 49 | $this->extensions = $extensions; |
||
| 50 | } |
||
| 51 | |||
| 52 | public function withName(LanguageMap $name = null): self |
||
| 53 | { |
||
| 54 | $definition = clone $this; |
||
| 55 | $definition->name = $name; |
||
| 56 | |||
| 57 | return $definition; |
||
| 58 | } |
||
| 59 | |||
| 60 | public function withDescription(LanguageMap $description = null): self |
||
| 61 | { |
||
| 62 | $definition = clone $this; |
||
| 63 | $definition->description = $description; |
||
| 64 | |||
| 65 | return $definition; |
||
| 66 | } |
||
| 67 | |||
| 68 | public function withType(IRI $type = null): self |
||
| 69 | { |
||
| 70 | $definition = clone $this; |
||
| 71 | $definition->type = $type; |
||
| 72 | |||
| 73 | return $definition; |
||
| 74 | } |
||
| 75 | |||
| 76 | public function withMoreInfo(IRL $moreInfo = null): self |
||
| 77 | { |
||
| 78 | $definition = clone $this; |
||
| 79 | $definition->moreInfo = $moreInfo; |
||
| 80 | |||
| 81 | return $definition; |
||
| 82 | } |
||
| 83 | |||
| 84 | public function withExtensions(Extensions $extensions): self |
||
| 85 | { |
||
| 86 | $definition = clone $this; |
||
| 87 | $definition->extensions = $extensions; |
||
| 88 | |||
| 89 | return $definition; |
||
| 90 | } |
||
| 91 | |||
| 92 | /** |
||
| 93 | * Returns the human readable names. |
||
| 94 | */ |
||
| 95 | public function getName(): ?LanguageMap |
||
| 96 | { |
||
| 97 | return $this->name; |
||
| 98 | } |
||
| 99 | |||
| 100 | /** |
||
| 101 | * Returns the human readable descriptions. |
||
| 102 | */ |
||
| 103 | public function getDescription(): ?LanguageMap |
||
| 104 | { |
||
| 105 | return $this->description; |
||
| 106 | } |
||
| 107 | |||
| 108 | /** |
||
| 109 | * Returns the {@link Activity} type. |
||
| 110 | */ |
||
| 111 | public function getType(): ?IRI |
||
| 112 | { |
||
| 113 | return $this->type; |
||
| 114 | } |
||
| 115 | |||
| 116 | /** |
||
| 117 | * Returns an IRL where human-readable information about the activity can be found. |
||
| 118 | */ |
||
| 119 | public function getMoreInfo(): ?IRL |
||
| 120 | { |
||
| 121 | return $this->moreInfo; |
||
| 122 | } |
||
| 123 | |||
| 124 | public function getExtensions(): ?Extensions |
||
| 125 | { |
||
| 126 | return $this->extensions; |
||
| 127 | } |
||
| 128 | |||
| 129 | /** |
||
| 130 | * Checks if another definition is equal. |
||
| 131 | * |
||
| 132 | * Two definitions are equal if and only if all of their properties are equal. |
||
| 133 | */ |
||
| 134 | public function equals(Definition $definition): bool |
||
| 135 | { |
||
| 136 | if (get_class($this) !== get_class($definition)) { |
||
| 137 | return false; |
||
| 138 | } |
||
| 139 | |||
| 140 | if (null !== $this->type xor null !== $definition->type) { |
||
| 141 | return false; |
||
| 142 | } |
||
| 143 | |||
| 144 | if (null !== $this->type && null !== $definition->type && !$this->type->equals($definition->type)) { |
||
| 145 | return false; |
||
| 146 | } |
||
| 147 | |||
| 148 | if (null !== $this->moreInfo xor null !== $definition->moreInfo) { |
||
| 149 | return false; |
||
| 150 | } |
||
| 151 | |||
| 152 | if (null !== $this->moreInfo && null !== $definition->moreInfo && !$this->moreInfo->equals($definition->moreInfo)) { |
||
| 153 | return false; |
||
| 154 | } |
||
| 155 | |||
| 156 | if (null !== $this->extensions xor null !== $definition->extensions) { |
||
| 157 | return false; |
||
| 158 | } |
||
| 159 | |||
| 160 | if (null !== $this->name xor null !== $definition->name) { |
||
| 161 | return false; |
||
| 162 | } |
||
| 163 | |||
| 164 | if (null !== $this->description xor null !== $definition->description) { |
||
| 165 | return false; |
||
| 166 | } |
||
| 167 | |||
| 168 | if (null !== $this->name) { |
||
| 169 | if (count($this->name) !== count($definition->name)) { |
||
| 170 | return false; |
||
| 171 | } |
||
| 172 | |||
| 173 | foreach ($this->name as $language => $value) { |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 174 | if (!isset($definition->name[$language])) { |
||
| 175 | return false; |
||
| 176 | } |
||
| 177 | |||
| 178 | if ($value !== $definition->name[$language]) { |
||
| 179 | return false; |
||
| 180 | } |
||
| 181 | } |
||
| 182 | } |
||
| 183 | |||
| 184 | if (null !== $this->description) { |
||
| 185 | if (count($this->description) !== count($definition->description)) { |
||
| 186 | return false; |
||
| 187 | } |
||
| 188 | |||
| 189 | foreach ($this->description as $language => $value) { |
||
|
0 ignored issues
–
show
|
|||
| 190 | if (!isset($definition->description[$language])) { |
||
| 191 | return false; |
||
| 192 | } |
||
| 193 | |||
| 194 | if ($value !== $definition->description[$language]) { |
||
| 195 | return false; |
||
| 196 | } |
||
| 197 | } |
||
| 198 | } |
||
| 199 | |||
| 200 | if (null !== $this->extensions && null !== $definition->extensions && !$this->extensions->equals($definition->extensions)) { |
||
| 201 | return false; |
||
| 202 | } |
||
| 203 | |||
| 204 | return true; |
||
| 205 | } |
||
| 206 | } |
||
| 207 |