| Total Complexity | 44 |
| Total Lines | 328 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Complex classes like XApiCmi5Item often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use XApiCmi5Item, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 11 | #[Gedmo\Tree(type: 'nested')] |
||
| 12 | #[ORM\Entity(repositoryClass: XApiCmi5ItemRepository::class)] |
||
| 13 | class XApiCmi5Item |
||
| 14 | { |
||
| 15 | #[ORM\Id] |
||
| 16 | #[ORM\GeneratedValue] |
||
| 17 | #[ORM\Column] |
||
| 18 | private ?int $id = null; |
||
| 19 | |||
| 20 | #[ORM\Column(length: 255)] |
||
| 21 | private ?string $identifier = null; |
||
| 22 | |||
| 23 | #[ORM\Column(length: 255)] |
||
| 24 | private ?string $type = null; |
||
| 25 | |||
| 26 | #[ORM\Column] |
||
| 27 | private array $title = []; |
||
| 28 | |||
| 29 | #[ORM\Column] |
||
| 30 | private array $description = []; |
||
| 31 | |||
| 32 | #[ORM\Column(length: 255, nullable: true)] |
||
| 33 | private ?string $url = null; |
||
| 34 | |||
| 35 | #[ORM\Column(length: 255, nullable: true)] |
||
| 36 | private ?string $activityType = null; |
||
| 37 | |||
| 38 | #[ORM\Column(length: 255, nullable: true)] |
||
| 39 | private ?string $launchMethod = null; |
||
| 40 | |||
| 41 | #[ORM\Column(length: 255, nullable: true)] |
||
| 42 | private ?string $moveOn = null; |
||
| 43 | |||
| 44 | #[ORM\Column(nullable: true)] |
||
| 45 | private ?float $masteryScore = null; |
||
| 46 | |||
| 47 | #[ORM\Column(length: 255, nullable: true)] |
||
| 48 | private ?string $launchParameters = null; |
||
| 49 | |||
| 50 | #[ORM\Column(length: 255, nullable: true)] |
||
| 51 | private ?string $entitlementKey = null; |
||
| 52 | |||
| 53 | #[ORM\Column(length: 255, nullable: true)] |
||
| 54 | private ?string $status = null; |
||
| 55 | |||
| 56 | #[Gedmo\TreeLeft] |
||
| 57 | #[ORM\Column] |
||
| 58 | private ?int $lft = null; |
||
| 59 | |||
| 60 | #[Gedmo\TreeLevel] |
||
| 61 | #[ORM\Column] |
||
| 62 | private ?int $lvl = null; |
||
| 63 | |||
| 64 | #[Gedmo\TreeRight] |
||
| 65 | #[ORM\Column] |
||
| 66 | private ?int $rgt = null; |
||
| 67 | |||
| 68 | #[Gedmo\TreeRoot] |
||
| 69 | #[ORM\ManyToOne(targetEntity: self::class)] |
||
| 70 | private ?self $root = null; |
||
| 71 | |||
| 72 | #[Gedmo\TreeParent] |
||
| 73 | #[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'children')] |
||
| 74 | private ?self $parent = null; |
||
| 75 | |||
| 76 | /** |
||
| 77 | * @var Collection<int, self> |
||
| 78 | */ |
||
| 79 | #[ORM\OneToMany(mappedBy: 'parent', targetEntity: self::class)] |
||
| 80 | private Collection $children; |
||
| 81 | |||
| 82 | #[ORM\ManyToOne(inversedBy: 'items')] |
||
| 83 | private ?XApiToolLaunch $tool = null; |
||
| 84 | |||
| 85 | public function __construct() |
||
| 86 | { |
||
| 87 | $this->children = new ArrayCollection(); |
||
| 88 | } |
||
| 89 | |||
| 90 | public function getId(): ?int |
||
| 91 | { |
||
| 92 | return $this->id; |
||
| 93 | } |
||
| 94 | |||
| 95 | public function getIdentifier(): ?string |
||
| 96 | { |
||
| 97 | return $this->identifier; |
||
| 98 | } |
||
| 99 | |||
| 100 | public function setIdentifier(string $identifier): static |
||
| 101 | { |
||
| 102 | $this->identifier = $identifier; |
||
| 103 | |||
| 104 | return $this; |
||
| 105 | } |
||
| 106 | |||
| 107 | public function getType(): ?string |
||
| 108 | { |
||
| 109 | return $this->type; |
||
| 110 | } |
||
| 111 | |||
| 112 | public function setType(string $type): static |
||
| 113 | { |
||
| 114 | $this->type = $type; |
||
| 115 | |||
| 116 | return $this; |
||
| 117 | } |
||
| 118 | |||
| 119 | public function getTitle(): array |
||
| 120 | { |
||
| 121 | return $this->title; |
||
| 122 | } |
||
| 123 | |||
| 124 | public function setTitle(array $title): static |
||
| 125 | { |
||
| 126 | $this->title = $title; |
||
| 127 | |||
| 128 | return $this; |
||
| 129 | } |
||
| 130 | |||
| 131 | public function getDescription(): array |
||
| 132 | { |
||
| 133 | return $this->description; |
||
| 134 | } |
||
| 135 | |||
| 136 | public function setDescription(array $description): static |
||
| 137 | { |
||
| 138 | $this->description = $description; |
||
| 139 | |||
| 140 | return $this; |
||
| 141 | } |
||
| 142 | |||
| 143 | public function getUrl(): ?string |
||
| 146 | } |
||
| 147 | |||
| 148 | public function setUrl(?string $url): static |
||
| 149 | { |
||
| 150 | $this->url = $url; |
||
| 151 | |||
| 152 | return $this; |
||
| 153 | } |
||
| 154 | |||
| 155 | public function getActivityType(): ?string |
||
| 156 | { |
||
| 157 | return $this->activityType; |
||
| 158 | } |
||
| 159 | |||
| 160 | public function setActivityType(?string $activityType): static |
||
| 161 | { |
||
| 162 | $this->activityType = $activityType; |
||
| 163 | |||
| 164 | return $this; |
||
| 165 | } |
||
| 166 | |||
| 167 | public function getLaunchMethod(): ?string |
||
| 168 | { |
||
| 169 | return $this->launchMethod; |
||
| 170 | } |
||
| 171 | |||
| 172 | public function setLaunchMethod(?string $launchMethod): static |
||
| 173 | { |
||
| 174 | $this->launchMethod = $launchMethod; |
||
| 175 | |||
| 176 | return $this; |
||
| 177 | } |
||
| 178 | |||
| 179 | public function getMoveOn(): ?string |
||
| 180 | { |
||
| 181 | return $this->moveOn; |
||
| 182 | } |
||
| 183 | |||
| 184 | public function setMoveOn(?string $moveOn): static |
||
| 185 | { |
||
| 186 | $this->moveOn = $moveOn; |
||
| 187 | |||
| 188 | return $this; |
||
| 189 | } |
||
| 190 | |||
| 191 | public function getMasteryScore(): ?float |
||
| 192 | { |
||
| 193 | return $this->masteryScore; |
||
| 194 | } |
||
| 195 | |||
| 196 | public function setMasteryScore(?float $masteryScore): static |
||
| 197 | { |
||
| 198 | $this->masteryScore = $masteryScore; |
||
| 199 | |||
| 200 | return $this; |
||
| 201 | } |
||
| 202 | |||
| 203 | public function getLaunchParameters(): ?string |
||
| 204 | { |
||
| 205 | return $this->launchParameters; |
||
| 206 | } |
||
| 207 | |||
| 208 | public function setLaunchParameters(?string $launchParameters): static |
||
| 209 | { |
||
| 210 | $this->launchParameters = $launchParameters; |
||
| 211 | |||
| 212 | return $this; |
||
| 213 | } |
||
| 214 | |||
| 215 | public function getEntitlementKey(): ?string |
||
| 216 | { |
||
| 217 | return $this->entitlementKey; |
||
| 218 | } |
||
| 219 | |||
| 220 | public function setEntitlementKey(?string $entitlementKey): static |
||
| 221 | { |
||
| 222 | $this->entitlementKey = $entitlementKey; |
||
| 223 | |||
| 224 | return $this; |
||
| 225 | } |
||
| 226 | |||
| 227 | public function getStatus(): ?string |
||
| 228 | { |
||
| 229 | return $this->status; |
||
| 230 | } |
||
| 231 | |||
| 232 | public function setStatus(?string $status): static |
||
| 233 | { |
||
| 234 | $this->status = $status; |
||
| 235 | |||
| 236 | return $this; |
||
| 237 | } |
||
| 238 | |||
| 239 | public function getLft(): ?int |
||
| 240 | { |
||
| 241 | return $this->lft; |
||
| 242 | } |
||
| 243 | |||
| 244 | public function setLft(int $lft): static |
||
| 249 | } |
||
| 250 | |||
| 251 | public function getñlvl(): ?int |
||
| 252 | { |
||
| 253 | return $this->lvl; |
||
| 254 | } |
||
| 255 | |||
| 256 | public function setñlvl(int $lvl): static |
||
| 257 | { |
||
| 258 | $this->lvl = $lvl; |
||
| 259 | |||
| 260 | return $this; |
||
| 261 | } |
||
| 262 | |||
| 263 | public function getRgt(): ?int |
||
| 264 | { |
||
| 265 | return $this->rgt; |
||
| 266 | } |
||
| 267 | |||
| 268 | public function setRgt(int $rgt): static |
||
| 269 | { |
||
| 270 | $this->rgt = $rgt; |
||
| 271 | |||
| 272 | return $this; |
||
| 273 | } |
||
| 274 | |||
| 275 | public function getRoot(): ?self |
||
| 276 | { |
||
| 277 | return $this->root; |
||
| 278 | } |
||
| 279 | |||
| 280 | public function setRoot(?self $root): static |
||
| 281 | { |
||
| 282 | $this->root = $root; |
||
| 283 | |||
| 284 | return $this; |
||
| 285 | } |
||
| 286 | |||
| 287 | public function getParent(): ?self |
||
| 288 | { |
||
| 289 | return $this->parent; |
||
| 290 | } |
||
| 291 | |||
| 292 | public function setParent(?self $parent): static |
||
| 293 | { |
||
| 294 | $this->parent = $parent; |
||
| 295 | |||
| 296 | return $this; |
||
| 297 | } |
||
| 298 | |||
| 299 | /** |
||
| 300 | * @return Collection<int, self> |
||
| 301 | */ |
||
| 302 | public function getChildren(): Collection |
||
| 305 | } |
||
| 306 | |||
| 307 | public function addChild(self $child): static |
||
| 308 | { |
||
| 309 | if (!$this->children->contains($child)) { |
||
| 310 | $this->children->add($child); |
||
| 311 | $child->setParent($this); |
||
| 312 | } |
||
| 313 | |||
| 314 | return $this; |
||
| 315 | } |
||
| 316 | |||
| 317 | public function removeChild(self $child): static |
||
| 318 | { |
||
| 319 | if ($this->children->removeElement($child)) { |
||
| 320 | // set the owning side to null (unless already changed) |
||
| 321 | if ($child->getParent() === $this) { |
||
| 322 | $child->setParent(null); |
||
| 323 | } |
||
| 324 | } |
||
| 325 | |||
| 326 | return $this; |
||
| 327 | } |
||
| 328 | |||
| 329 | public function getTool(): ?XApiToolLaunch |
||
| 332 | } |
||
| 333 | |||
| 334 | public function setTool(?XApiToolLaunch $tool): static |
||
| 335 | { |
||
| 336 | $this->tool = $tool; |
||
| 337 | |||
| 338 | return $this; |
||
| 339 | } |
||
| 340 | } |
||
| 341 |