| 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 |
||
| 15 | #[Gedmo\Tree(type: 'nested')] |
||
| 16 | #[ORM\Entity(repositoryClass: XApiCmi5ItemRepository::class)] |
||
| 17 | class XApiCmi5Item |
||
| 18 | { |
||
| 19 | #[ORM\Id] |
||
| 20 | #[ORM\GeneratedValue] |
||
| 21 | #[ORM\Column] |
||
| 22 | private ?int $id = null; |
||
| 23 | |||
| 24 | #[ORM\Column(length: 255)] |
||
| 25 | private ?string $identifier = null; |
||
| 26 | |||
| 27 | #[ORM\Column(length: 255)] |
||
| 28 | private ?string $type = null; |
||
| 29 | |||
| 30 | #[ORM\Column] |
||
| 31 | private array $title = []; |
||
| 32 | |||
| 33 | #[ORM\Column] |
||
| 34 | private array $description = []; |
||
| 35 | |||
| 36 | #[ORM\Column(length: 255, nullable: true)] |
||
| 37 | private ?string $url = null; |
||
| 38 | |||
| 39 | #[ORM\Column(length: 255, nullable: true)] |
||
| 40 | private ?string $activityType = null; |
||
| 41 | |||
| 42 | #[ORM\Column(length: 255, nullable: true)] |
||
| 43 | private ?string $launchMethod = null; |
||
| 44 | |||
| 45 | #[ORM\Column(length: 255, nullable: true)] |
||
| 46 | private ?string $moveOn = null; |
||
| 47 | |||
| 48 | #[ORM\Column(nullable: true)] |
||
| 49 | private ?float $masteryScore = null; |
||
| 50 | |||
| 51 | #[ORM\Column(length: 255, nullable: true)] |
||
| 52 | private ?string $launchParameters = null; |
||
| 53 | |||
| 54 | #[ORM\Column(length: 255, nullable: true)] |
||
| 55 | private ?string $entitlementKey = null; |
||
| 56 | |||
| 57 | #[ORM\Column(length: 255, nullable: true)] |
||
| 58 | private ?string $status = null; |
||
| 59 | |||
| 60 | #[Gedmo\TreeLeft] |
||
| 61 | #[ORM\Column] |
||
| 62 | private ?int $lft = null; |
||
| 63 | |||
| 64 | #[Gedmo\TreeLevel] |
||
| 65 | #[ORM\Column] |
||
| 66 | private ?int $lvl = null; |
||
| 67 | |||
| 68 | #[Gedmo\TreeRight] |
||
| 69 | #[ORM\Column] |
||
| 70 | private ?int $rgt = null; |
||
| 71 | |||
| 72 | #[Gedmo\TreeRoot] |
||
| 73 | #[ORM\ManyToOne(targetEntity: self::class)] |
||
| 74 | private ?self $root = null; |
||
| 75 | |||
| 76 | #[Gedmo\TreeParent] |
||
| 77 | #[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'children')] |
||
| 78 | private ?self $parent = null; |
||
| 79 | |||
| 80 | /** |
||
| 81 | * @var Collection<int, self> |
||
| 82 | */ |
||
| 83 | #[ORM\OneToMany(mappedBy: 'parent', targetEntity: self::class)] |
||
| 84 | private Collection $children; |
||
| 85 | |||
| 86 | #[ORM\ManyToOne(inversedBy: 'items')] |
||
| 87 | private ?XApiToolLaunch $tool = null; |
||
| 88 | |||
| 89 | public function __construct() |
||
| 90 | { |
||
| 91 | $this->children = new ArrayCollection(); |
||
| 92 | } |
||
| 93 | |||
| 94 | public function getId(): ?int |
||
| 95 | { |
||
| 96 | return $this->id; |
||
| 97 | } |
||
| 98 | |||
| 99 | public function getIdentifier(): ?string |
||
| 100 | { |
||
| 101 | return $this->identifier; |
||
| 102 | } |
||
| 103 | |||
| 104 | public function setIdentifier(string $identifier): static |
||
| 105 | { |
||
| 106 | $this->identifier = $identifier; |
||
| 107 | |||
| 108 | return $this; |
||
| 109 | } |
||
| 110 | |||
| 111 | public function getType(): ?string |
||
| 112 | { |
||
| 113 | return $this->type; |
||
| 114 | } |
||
| 115 | |||
| 116 | public function setType(string $type): static |
||
| 117 | { |
||
| 118 | $this->type = $type; |
||
| 119 | |||
| 120 | return $this; |
||
| 121 | } |
||
| 122 | |||
| 123 | public function getTitle(): array |
||
| 124 | { |
||
| 125 | return $this->title; |
||
| 126 | } |
||
| 127 | |||
| 128 | public function setTitle(array $title): static |
||
| 129 | { |
||
| 130 | $this->title = $title; |
||
| 131 | |||
| 132 | return $this; |
||
| 133 | } |
||
| 134 | |||
| 135 | public function getDescription(): array |
||
| 136 | { |
||
| 137 | return $this->description; |
||
| 138 | } |
||
| 139 | |||
| 140 | public function setDescription(array $description): static |
||
| 141 | { |
||
| 142 | $this->description = $description; |
||
| 143 | |||
| 144 | return $this; |
||
| 145 | } |
||
| 146 | |||
| 147 | public function getUrl(): ?string |
||
| 150 | } |
||
| 151 | |||
| 152 | public function setUrl(?string $url): static |
||
| 153 | { |
||
| 154 | $this->url = $url; |
||
| 155 | |||
| 156 | return $this; |
||
| 157 | } |
||
| 158 | |||
| 159 | public function getActivityType(): ?string |
||
| 160 | { |
||
| 161 | return $this->activityType; |
||
| 162 | } |
||
| 163 | |||
| 164 | public function setActivityType(?string $activityType): static |
||
| 165 | { |
||
| 166 | $this->activityType = $activityType; |
||
| 167 | |||
| 168 | return $this; |
||
| 169 | } |
||
| 170 | |||
| 171 | public function getLaunchMethod(): ?string |
||
| 172 | { |
||
| 173 | return $this->launchMethod; |
||
| 174 | } |
||
| 175 | |||
| 176 | public function setLaunchMethod(?string $launchMethod): static |
||
| 177 | { |
||
| 178 | $this->launchMethod = $launchMethod; |
||
| 179 | |||
| 180 | return $this; |
||
| 181 | } |
||
| 182 | |||
| 183 | public function getMoveOn(): ?string |
||
| 184 | { |
||
| 185 | return $this->moveOn; |
||
| 186 | } |
||
| 187 | |||
| 188 | public function setMoveOn(?string $moveOn): static |
||
| 189 | { |
||
| 190 | $this->moveOn = $moveOn; |
||
| 191 | |||
| 192 | return $this; |
||
| 193 | } |
||
| 194 | |||
| 195 | public function getMasteryScore(): ?float |
||
| 196 | { |
||
| 197 | return $this->masteryScore; |
||
| 198 | } |
||
| 199 | |||
| 200 | public function setMasteryScore(?float $masteryScore): static |
||
| 201 | { |
||
| 202 | $this->masteryScore = $masteryScore; |
||
| 203 | |||
| 204 | return $this; |
||
| 205 | } |
||
| 206 | |||
| 207 | public function getLaunchParameters(): ?string |
||
| 208 | { |
||
| 209 | return $this->launchParameters; |
||
| 210 | } |
||
| 211 | |||
| 212 | public function setLaunchParameters(?string $launchParameters): static |
||
| 213 | { |
||
| 214 | $this->launchParameters = $launchParameters; |
||
| 215 | |||
| 216 | return $this; |
||
| 217 | } |
||
| 218 | |||
| 219 | public function getEntitlementKey(): ?string |
||
| 220 | { |
||
| 221 | return $this->entitlementKey; |
||
| 222 | } |
||
| 223 | |||
| 224 | public function setEntitlementKey(?string $entitlementKey): static |
||
| 225 | { |
||
| 226 | $this->entitlementKey = $entitlementKey; |
||
| 227 | |||
| 228 | return $this; |
||
| 229 | } |
||
| 230 | |||
| 231 | public function getStatus(): ?string |
||
| 232 | { |
||
| 233 | return $this->status; |
||
| 234 | } |
||
| 235 | |||
| 236 | public function setStatus(?string $status): static |
||
| 237 | { |
||
| 238 | $this->status = $status; |
||
| 239 | |||
| 240 | return $this; |
||
| 241 | } |
||
| 242 | |||
| 243 | public function getLft(): ?int |
||
| 244 | { |
||
| 245 | return $this->lft; |
||
| 246 | } |
||
| 247 | |||
| 248 | public function setLft(int $lft): static |
||
| 253 | } |
||
| 254 | |||
| 255 | public function getñlvl(): ?int |
||
| 256 | { |
||
| 257 | return $this->lvl; |
||
| 258 | } |
||
| 259 | |||
| 260 | public function setñlvl(int $lvl): static |
||
| 261 | { |
||
| 262 | $this->lvl = $lvl; |
||
| 263 | |||
| 264 | return $this; |
||
| 265 | } |
||
| 266 | |||
| 267 | public function getRgt(): ?int |
||
| 268 | { |
||
| 269 | return $this->rgt; |
||
| 270 | } |
||
| 271 | |||
| 272 | public function setRgt(int $rgt): static |
||
| 273 | { |
||
| 274 | $this->rgt = $rgt; |
||
| 275 | |||
| 276 | return $this; |
||
| 277 | } |
||
| 278 | |||
| 279 | public function getRoot(): ?self |
||
| 280 | { |
||
| 281 | return $this->root; |
||
| 282 | } |
||
| 283 | |||
| 284 | public function setRoot(?self $root): static |
||
| 285 | { |
||
| 286 | $this->root = $root; |
||
| 287 | |||
| 288 | return $this; |
||
| 289 | } |
||
| 290 | |||
| 291 | public function getParent(): ?self |
||
| 292 | { |
||
| 293 | return $this->parent; |
||
| 294 | } |
||
| 295 | |||
| 296 | public function setParent(?self $parent): static |
||
| 297 | { |
||
| 298 | $this->parent = $parent; |
||
| 299 | |||
| 300 | return $this; |
||
| 301 | } |
||
| 302 | |||
| 303 | /** |
||
| 304 | * @return Collection<int, self> |
||
| 305 | */ |
||
| 306 | public function getChildren(): Collection |
||
| 309 | } |
||
| 310 | |||
| 311 | public function addChild(self $child): static |
||
| 312 | { |
||
| 313 | if (!$this->children->contains($child)) { |
||
| 314 | $this->children->add($child); |
||
| 315 | $child->setParent($this); |
||
| 316 | } |
||
| 317 | |||
| 318 | return $this; |
||
| 319 | } |
||
| 320 | |||
| 321 | public function removeChild(self $child): static |
||
| 322 | { |
||
| 323 | if ($this->children->removeElement($child)) { |
||
| 324 | // set the owning side to null (unless already changed) |
||
| 325 | if ($child->getParent() === $this) { |
||
| 326 | $child->setParent(null); |
||
| 327 | } |
||
| 328 | } |
||
| 329 | |||
| 330 | return $this; |
||
| 331 | } |
||
| 332 | |||
| 333 | public function getTool(): ?XApiToolLaunch |
||
| 336 | } |
||
| 337 | |||
| 338 | public function setTool(?XApiToolLaunch $tool): static |
||
| 339 | { |
||
| 340 | $this->tool = $tool; |
||
| 341 | |||
| 342 | return $this; |
||
| 343 | } |
||
| 344 | } |
||
| 345 |