| Total Complexity | 44 |
| Total Lines | 301 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Complex classes like XApiContext 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 XApiContext, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 14 | #[ORM\Entity(repositoryClass: XApiContextRepository::class)] |
||
| 15 | class XApiContext |
||
| 16 | { |
||
| 17 | #[ORM\Id] |
||
| 18 | #[ORM\GeneratedValue] |
||
| 19 | #[ORM\Column] |
||
| 20 | private ?int $identifier = null; |
||
| 21 | |||
| 22 | #[ORM\Column(length: 255, nullable: true)] |
||
| 23 | private ?string $registration = null; |
||
| 24 | |||
| 25 | #[ORM\Column(nullable: true)] |
||
| 26 | private ?bool $hasContextActivities = null; |
||
| 27 | |||
| 28 | #[ORM\Column(length: 255, nullable: true)] |
||
| 29 | private ?string $revision = null; |
||
| 30 | |||
| 31 | #[ORM\Column(length: 255, nullable: true)] |
||
| 32 | private ?string $platform = null; |
||
| 33 | |||
| 34 | #[ORM\Column(length: 255, nullable: true)] |
||
| 35 | private ?string $language = null; |
||
| 36 | |||
| 37 | #[ORM\Column(length: 255, nullable: true)] |
||
| 38 | private ?string $statement = null; |
||
| 39 | |||
| 40 | #[ORM\OneToOne(cascade: ['persist', 'remove'])] |
||
| 41 | #[ORM\JoinColumn(referencedColumnName: 'identifier')] |
||
| 42 | private ?XApiObject $instructor = null; |
||
| 43 | |||
| 44 | #[ORM\OneToOne(cascade: ['persist', 'remove'])] |
||
| 45 | #[ORM\JoinColumn(referencedColumnName: 'identifier')] |
||
| 46 | private ?XApiObject $team = null; |
||
| 47 | |||
| 48 | #[ORM\OneToOne(cascade: ['persist', 'remove'])] |
||
| 49 | #[ORM\JoinColumn(referencedColumnName: 'identifier')] |
||
| 50 | private ?XApiExtensions $extensions = null; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * @var Collection<int, XApiObject> |
||
| 54 | */ |
||
| 55 | #[ORM\OneToMany(mappedBy: 'parentContext', targetEntity: XApiObject::class)] |
||
| 56 | private Collection $parentActivities; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @var Collection<int, XApiObject> |
||
| 60 | */ |
||
| 61 | #[ORM\OneToMany(mappedBy: 'groupingContext', targetEntity: XApiObject::class)] |
||
| 62 | private Collection $groupingActivities; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @var Collection<int, XApiObject> |
||
| 66 | */ |
||
| 67 | #[ORM\OneToMany(mappedBy: 'categoryContext', targetEntity: XApiObject::class)] |
||
| 68 | private Collection $categoryActivities; |
||
| 69 | |||
| 70 | /** |
||
| 71 | * @var Collection<int, XApiObject> |
||
| 72 | */ |
||
| 73 | #[ORM\OneToMany(mappedBy: 'otherContext', targetEntity: XApiObject::class)] |
||
| 74 | private Collection $otherActivities; |
||
| 75 | |||
| 76 | public function __construct() |
||
| 77 | { |
||
| 78 | $this->parentActivities = new ArrayCollection(); |
||
| 79 | $this->groupingActivities = new ArrayCollection(); |
||
| 80 | $this->categoryActivities = new ArrayCollection(); |
||
| 81 | $this->otherActivities = new ArrayCollection(); |
||
| 82 | } |
||
| 83 | |||
| 84 | public function getIdentifier(): ?int |
||
| 85 | { |
||
| 86 | return $this->identifier; |
||
| 87 | } |
||
| 88 | |||
| 89 | public function getRegistration(): ?string |
||
| 90 | { |
||
| 91 | return $this->registration; |
||
| 92 | } |
||
| 93 | |||
| 94 | public function setRegistration(?string $registration): static |
||
| 95 | { |
||
| 96 | $this->registration = $registration; |
||
| 97 | |||
| 98 | return $this; |
||
| 99 | } |
||
| 100 | |||
| 101 | public function hasContextActivities(): ?bool |
||
| 104 | } |
||
| 105 | |||
| 106 | public function setHasContextActivities(?bool $hasContextActivities): static |
||
| 107 | { |
||
| 108 | $this->hasContextActivities = $hasContextActivities; |
||
| 109 | |||
| 110 | return $this; |
||
| 111 | } |
||
| 112 | |||
| 113 | public function getRevision(): ?string |
||
| 114 | { |
||
| 115 | return $this->revision; |
||
| 116 | } |
||
| 117 | |||
| 118 | public function setRevision(?string $revision): static |
||
| 119 | { |
||
| 120 | $this->revision = $revision; |
||
| 121 | |||
| 122 | return $this; |
||
| 123 | } |
||
| 124 | |||
| 125 | public function getPlatform(): ?string |
||
| 126 | { |
||
| 127 | return $this->platform; |
||
| 128 | } |
||
| 129 | |||
| 130 | public function setPlatform(?string $platform): static |
||
| 135 | } |
||
| 136 | |||
| 137 | public function getLanguage(): ?string |
||
| 138 | { |
||
| 139 | return $this->language; |
||
| 140 | } |
||
| 141 | |||
| 142 | public function setLanguage(?string $language): static |
||
| 143 | { |
||
| 144 | $this->language = $language; |
||
| 145 | |||
| 146 | return $this; |
||
| 147 | } |
||
| 148 | |||
| 149 | public function getStatement(): ?string |
||
| 150 | { |
||
| 151 | return $this->statement; |
||
| 152 | } |
||
| 153 | |||
| 154 | public function setStatement(?string $statement): static |
||
| 155 | { |
||
| 156 | $this->statement = $statement; |
||
| 157 | |||
| 158 | return $this; |
||
| 159 | } |
||
| 160 | |||
| 161 | public function getInstructor(): ?XApiObject |
||
| 162 | { |
||
| 163 | return $this->instructor; |
||
| 164 | } |
||
| 165 | |||
| 166 | public function setInstructor(?XApiObject $instructor): static |
||
| 167 | { |
||
| 168 | $this->instructor = $instructor; |
||
| 169 | |||
| 170 | return $this; |
||
| 171 | } |
||
| 172 | |||
| 173 | public function getTeam(): ?XApiObject |
||
| 174 | { |
||
| 175 | return $this->team; |
||
| 176 | } |
||
| 177 | |||
| 178 | public function setTeam(?XApiObject $team): static |
||
| 179 | { |
||
| 180 | $this->team = $team; |
||
| 181 | |||
| 182 | return $this; |
||
| 183 | } |
||
| 184 | |||
| 185 | public function getExtensions(): ?XApiExtensions |
||
| 186 | { |
||
| 187 | return $this->extensions; |
||
| 188 | } |
||
| 189 | |||
| 190 | public function setExtensions(?XApiExtensions $extensions): static |
||
| 191 | { |
||
| 192 | $this->extensions = $extensions; |
||
| 193 | |||
| 194 | return $this; |
||
| 195 | } |
||
| 196 | |||
| 197 | /** |
||
| 198 | * @return Collection<int, XApiObject> |
||
| 199 | */ |
||
| 200 | public function getParentActivities(): Collection |
||
| 201 | { |
||
| 202 | return $this->parentActivities; |
||
| 203 | } |
||
| 204 | |||
| 205 | public function addParentActivity(XApiObject $parentActivity): static |
||
| 206 | { |
||
| 207 | if (!$this->parentActivities->contains($parentActivity)) { |
||
| 208 | $this->parentActivities->add($parentActivity); |
||
| 209 | $parentActivity->setParentContext($this); |
||
| 210 | } |
||
| 211 | |||
| 212 | return $this; |
||
| 213 | } |
||
| 214 | |||
| 215 | public function removeParentActivity(XApiObject $parentActivity): static |
||
| 216 | { |
||
| 217 | if ($this->parentActivities->removeElement($parentActivity)) { |
||
| 218 | // set the owning side to null (unless already changed) |
||
| 219 | if ($parentActivity->getParentContext() === $this) { |
||
| 220 | $parentActivity->setParentContext(null); |
||
| 221 | } |
||
| 222 | } |
||
| 223 | |||
| 224 | return $this; |
||
| 225 | } |
||
| 226 | |||
| 227 | /** |
||
| 228 | * @return Collection<int, XApiObject> |
||
| 229 | */ |
||
| 230 | public function getGroupingActivities(): Collection |
||
| 231 | { |
||
| 232 | return $this->groupingActivities; |
||
| 233 | } |
||
| 234 | |||
| 235 | public function addGroupingActivity(XApiObject $groupingActivity): static |
||
| 236 | { |
||
| 237 | if (!$this->groupingActivities->contains($groupingActivity)) { |
||
| 238 | $this->groupingActivities->add($groupingActivity); |
||
| 239 | $groupingActivity->setGroupingContext($this); |
||
| 240 | } |
||
| 241 | |||
| 242 | return $this; |
||
| 243 | } |
||
| 244 | |||
| 245 | public function removeGroupingActivity(XApiObject $groupingActivity): static |
||
| 246 | { |
||
| 247 | if ($this->groupingActivities->removeElement($groupingActivity)) { |
||
| 248 | // set the owning side to null (unless already changed) |
||
| 249 | if ($groupingActivity->getGroupingContext() === $this) { |
||
| 250 | $groupingActivity->setGroupingContext(null); |
||
| 251 | } |
||
| 252 | } |
||
| 253 | |||
| 254 | return $this; |
||
| 255 | } |
||
| 256 | |||
| 257 | /** |
||
| 258 | * @return Collection<int, XApiObject> |
||
| 259 | */ |
||
| 260 | public function getCategoryActivities(): Collection |
||
| 261 | { |
||
| 262 | return $this->categoryActivities; |
||
| 263 | } |
||
| 264 | |||
| 265 | public function addCategoryActivity(XApiObject $categoryActivity): static |
||
| 266 | { |
||
| 267 | if (!$this->categoryActivities->contains($categoryActivity)) { |
||
| 268 | $this->categoryActivities->add($categoryActivity); |
||
| 269 | $categoryActivity->setCategoryContext($this); |
||
| 270 | } |
||
| 271 | |||
| 272 | return $this; |
||
| 273 | } |
||
| 274 | |||
| 275 | public function removeCategoryActivity(XApiObject $categoryActivity): static |
||
| 276 | { |
||
| 277 | if ($this->categoryActivities->removeElement($categoryActivity)) { |
||
| 278 | // set the owning side to null (unless already changed) |
||
| 279 | if ($categoryActivity->getCategoryContext() === $this) { |
||
| 280 | $categoryActivity->setCategoryContext(null); |
||
| 281 | } |
||
| 282 | } |
||
| 283 | |||
| 284 | return $this; |
||
| 285 | } |
||
| 286 | |||
| 287 | /** |
||
| 288 | * @return Collection<int, XApiObject> |
||
| 289 | */ |
||
| 290 | public function getOtherActivities(): Collection |
||
| 291 | { |
||
| 292 | return $this->otherActivities; |
||
| 293 | } |
||
| 294 | |||
| 295 | public function addOtherActivity(XApiObject $otherActivity): static |
||
| 296 | { |
||
| 297 | if (!$this->otherActivities->contains($otherActivity)) { |
||
| 298 | $this->otherActivities->add($otherActivity); |
||
| 299 | $otherActivity->setOtherContext($this); |
||
| 300 | } |
||
| 301 | |||
| 302 | return $this; |
||
| 303 | } |
||
| 304 | |||
| 305 | public function removeOtherActivity(XApiObject $otherActivity): static |
||
| 315 | } |
||
| 316 | } |
||
| 317 |