| Total Complexity | 44 |
| Total Lines | 360 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like H5pImportLibrary 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 H5pImportLibrary, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 22 | class H5pImportLibrary extends EntityRepository |
||
| 23 | { |
||
| 24 | /** |
||
| 25 | * @var \DateTime |
||
| 26 | * |
||
| 27 | * @Gedmo\Timestampable(on="create") |
||
| 28 | * |
||
| 29 | * @ORM\Column(name="created_at", type="datetime", nullable=false) |
||
| 30 | */ |
||
| 31 | protected $createdAt; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @var \DateTime |
||
| 35 | * |
||
| 36 | * @Gedmo\Timestampable(on="update") |
||
| 37 | * |
||
| 38 | * @ORM\Column(name="modified_at", type="datetime", nullable=false) |
||
| 39 | */ |
||
| 40 | protected $modifiedAt; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @var int |
||
| 44 | * |
||
| 45 | * @ORM\Column(name="iid", type="integer") |
||
| 46 | * |
||
| 47 | * @ORM\Id |
||
| 48 | * |
||
| 49 | * @ORM\GeneratedValue |
||
| 50 | */ |
||
| 51 | private $iid; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @ORM\Column(name="title", type="string", nullable=true) |
||
| 55 | */ |
||
| 56 | private $title; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @ORM\Column(name="machine_name", type="string") |
||
| 60 | */ |
||
| 61 | private $machineName; |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @ORM\Column(name="major_version", type="integer") |
||
| 65 | */ |
||
| 66 | private $majorVersion; |
||
| 67 | |||
| 68 | /** |
||
| 69 | * @ORM\Column(name="minor_version", type="integer") |
||
| 70 | */ |
||
| 71 | private $minorVersion; |
||
| 72 | |||
| 73 | /** |
||
| 74 | * @ORM\Column(name="patch_version", type="integer") |
||
| 75 | */ |
||
| 76 | private $patchVersion; |
||
| 77 | |||
| 78 | /** |
||
| 79 | * @ORM\Column(name="runnable", type="integer", nullable=true) |
||
| 80 | */ |
||
| 81 | private $runnable; |
||
| 82 | |||
| 83 | /** |
||
| 84 | * @ORM\Column(name="embed_types", type="array", nullable=true) |
||
| 85 | */ |
||
| 86 | private $embedTypes; |
||
| 87 | |||
| 88 | /** |
||
| 89 | * @ORM\Column(name="preloaded_js" , type="array", nullable=true) |
||
| 90 | */ |
||
| 91 | private $preloadedJs; |
||
| 92 | |||
| 93 | /** |
||
| 94 | * @ORM\Column(name="preloaded_css", type="array", nullable=true) |
||
| 95 | */ |
||
| 96 | private $preloadedCss; |
||
| 97 | |||
| 98 | /** |
||
| 99 | * @ORM\Column(name="library_path", type="string", length=255) |
||
| 100 | */ |
||
| 101 | private $libraryPath; |
||
| 102 | |||
| 103 | /** |
||
| 104 | * @var Collection<int, H5pImport> |
||
| 105 | * |
||
| 106 | * @ORM\ManyToMany(targetEntity="H5pImport", inversedBy="libraries") |
||
| 107 | * |
||
| 108 | * @ORM\JoinTable( |
||
| 109 | * name="plugin_h5p_import_rel_libraries", |
||
| 110 | * joinColumns={@ORM\JoinColumn(name="h5p_import_library_id", referencedColumnName="iid", onDelete="CASCADE")}, |
||
| 111 | * inverseJoinColumns={@ORM\JoinColumn(name="h5p_import_id", referencedColumnName="iid", onDelete="CASCADE")} |
||
| 112 | * ) |
||
| 113 | */ |
||
| 114 | private $h5pImports; |
||
| 115 | |||
| 116 | /** |
||
| 117 | * @var Course |
||
| 118 | * |
||
| 119 | * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Course") |
||
| 120 | * |
||
| 121 | * @ORM\JoinColumn(name="c_id", referencedColumnName="id", nullable=false) |
||
| 122 | */ |
||
| 123 | private $course; |
||
| 124 | |||
| 125 | public function __construct() |
||
| 126 | { |
||
| 127 | $this->h5pImports = new ArrayCollection(); |
||
| 128 | } |
||
| 129 | |||
| 130 | public function getIid(): int |
||
| 131 | { |
||
| 132 | return $this->iid; |
||
| 133 | } |
||
| 134 | |||
| 135 | public function setIid(int $iid): H5pImportLibrary |
||
| 136 | { |
||
| 137 | $this->iid = $iid; |
||
| 138 | |||
| 139 | return $this; |
||
| 140 | } |
||
| 141 | |||
| 142 | public function getMachineName(): string |
||
| 143 | { |
||
| 144 | return $this->machineName; |
||
| 145 | } |
||
| 146 | |||
| 147 | public function setMachineName(string $machineName): H5pImportLibrary |
||
| 148 | { |
||
| 149 | $this->machineName = $machineName; |
||
| 150 | |||
| 151 | return $this; |
||
| 152 | } |
||
| 153 | |||
| 154 | public function getTitle(): string |
||
| 155 | { |
||
| 156 | return $this->title; |
||
|
|
|||
| 157 | } |
||
| 158 | |||
| 159 | public function setTitle(string $title): H5pImportLibrary |
||
| 160 | { |
||
| 161 | $this->title = $title; |
||
| 162 | |||
| 163 | return $this; |
||
| 164 | } |
||
| 165 | |||
| 166 | public function getMajorVersion(): int |
||
| 167 | { |
||
| 168 | return $this->majorVersion; |
||
| 169 | } |
||
| 170 | |||
| 171 | public function setMajorVersion(int $majorVersion): H5pImportLibrary |
||
| 172 | { |
||
| 173 | $this->majorVersion = $majorVersion; |
||
| 174 | |||
| 175 | return $this; |
||
| 176 | } |
||
| 177 | |||
| 178 | public function getMinorVersion(): int |
||
| 179 | { |
||
| 180 | return $this->minorVersion; |
||
| 181 | } |
||
| 182 | |||
| 183 | public function setMinorVersion(int $minorVersion): H5pImportLibrary |
||
| 184 | { |
||
| 185 | $this->minorVersion = $minorVersion; |
||
| 186 | |||
| 187 | return $this; |
||
| 188 | } |
||
| 189 | |||
| 190 | public function getPatchVersion(): int |
||
| 191 | { |
||
| 192 | return $this->patchVersion; |
||
| 193 | } |
||
| 194 | |||
| 195 | public function setPatchVersion(int $patchVersion): H5pImportLibrary |
||
| 196 | { |
||
| 197 | $this->patchVersion = $patchVersion; |
||
| 198 | |||
| 199 | return $this; |
||
| 200 | } |
||
| 201 | |||
| 202 | public function getRunnable(): int |
||
| 203 | { |
||
| 204 | return $this->runnable; |
||
| 205 | } |
||
| 206 | |||
| 207 | public function setRunnable(?int $runnable): H5pImportLibrary |
||
| 208 | { |
||
| 209 | $this->runnable = $runnable; |
||
| 210 | |||
| 211 | return $this; |
||
| 212 | } |
||
| 213 | |||
| 214 | /** |
||
| 215 | * @return array |
||
| 216 | */ |
||
| 217 | public function getPreloadedJs(): ?array |
||
| 218 | { |
||
| 219 | return $this->preloadedJs; |
||
| 220 | } |
||
| 221 | |||
| 222 | public function setPreloadedJs(?array $preloadedJs): H5pImportLibrary |
||
| 223 | { |
||
| 224 | $this->preloadedJs = $preloadedJs; |
||
| 225 | |||
| 226 | return $this; |
||
| 227 | } |
||
| 228 | |||
| 229 | /** |
||
| 230 | * @return array |
||
| 231 | */ |
||
| 232 | public function getPreloadedCss(): ?array |
||
| 233 | { |
||
| 234 | return $this->preloadedCss; |
||
| 235 | } |
||
| 236 | |||
| 237 | public function setPreloadedCss(?array $preloadedCss): H5pImportLibrary |
||
| 238 | { |
||
| 239 | $this->preloadedCss = $preloadedCss; |
||
| 240 | |||
| 241 | return $this; |
||
| 242 | } |
||
| 243 | |||
| 244 | public function getEmbedTypes(): ?array |
||
| 245 | { |
||
| 246 | return $this->embedTypes; |
||
| 247 | } |
||
| 248 | |||
| 249 | public function setEmbedTypes(?array $embedTypes): H5pImportLibrary |
||
| 254 | } |
||
| 255 | |||
| 256 | public function getLibraryPath(): string |
||
| 257 | { |
||
| 258 | return $this->libraryPath; |
||
| 259 | } |
||
| 260 | |||
| 261 | public function setLibraryPath(string $libraryPath): H5pImportLibrary |
||
| 262 | { |
||
| 263 | $this->libraryPath = $libraryPath; |
||
| 264 | |||
| 265 | return $this; |
||
| 266 | } |
||
| 267 | |||
| 268 | public function addH5pImport(H5pImport $h5pImport): self |
||
| 269 | { |
||
| 270 | if (!$this->h5pImports->contains($h5pImport)) { |
||
| 271 | $this->h5pImports[] = $h5pImport; |
||
| 272 | } |
||
| 273 | |||
| 274 | return $this; |
||
| 275 | } |
||
| 276 | |||
| 277 | public function removeH5pImport(H5pImport $h5pImport): self |
||
| 278 | { |
||
| 279 | $this->h5pImports->removeElement($h5pImport); |
||
| 280 | |||
| 281 | return $this; |
||
| 282 | } |
||
| 283 | |||
| 284 | public function getH5pImports(): Collection |
||
| 285 | { |
||
| 286 | return $this->h5pImports; |
||
| 287 | } |
||
| 288 | |||
| 289 | public function getCourse(): Course |
||
| 290 | { |
||
| 291 | return $this->course; |
||
| 292 | } |
||
| 293 | |||
| 294 | public function setCourse(Course $course): self |
||
| 295 | { |
||
| 296 | $this->course = $course; |
||
| 297 | |||
| 298 | return $this; |
||
| 299 | } |
||
| 300 | |||
| 301 | public function getCreatedAt(): \DateTime |
||
| 302 | { |
||
| 303 | return $this->createdAt; |
||
| 304 | } |
||
| 305 | |||
| 306 | public function setCreatedAt(\DateTime $createdAt): H5pImportLibrary |
||
| 307 | { |
||
| 308 | $this->createdAt = $createdAt; |
||
| 309 | |||
| 310 | return $this; |
||
| 311 | } |
||
| 312 | |||
| 313 | public function getModifiedAt(): \DateTime |
||
| 314 | { |
||
| 315 | return $this->modifiedAt; |
||
| 316 | } |
||
| 317 | |||
| 318 | public function setModifiedAt(\DateTime $modifiedAt): H5pImportLibrary |
||
| 319 | { |
||
| 320 | $this->modifiedAt = $modifiedAt; |
||
| 321 | |||
| 322 | return $this; |
||
| 323 | } |
||
| 324 | |||
| 325 | public function getLibraryByMachineNameAndVersions(string $machineName, int $majorVersion, int $minorVersion) |
||
| 326 | { |
||
| 327 | if ( |
||
| 328 | $this->machineName === $machineName |
||
| 329 | && $this->majorVersion === $majorVersion |
||
| 330 | && $this->minorVersion === $minorVersion |
||
| 331 | ) { |
||
| 332 | return $this; |
||
| 333 | } |
||
| 334 | |||
| 335 | return false; |
||
| 336 | } |
||
| 337 | |||
| 338 | /** |
||
| 339 | * Get the preloaded JS array of the imported library formatted as a comma-separated string. |
||
| 340 | * |
||
| 341 | * @return string the preloaded JS array of the imported library formatted as a comma-separated string |
||
| 342 | */ |
||
| 343 | public function getPreloadedJsFormatted(): string |
||
| 344 | { |
||
| 345 | $formattedJs = []; |
||
| 346 | |||
| 347 | foreach ($this->preloadedJs as $value) { |
||
| 348 | if (is_string($value->path)) { |
||
| 349 | $formattedJs[] = $value->path; |
||
| 350 | } |
||
| 351 | } |
||
| 352 | |||
| 353 | return implode(',', $formattedJs); |
||
| 354 | } |
||
| 355 | |||
| 356 | /** |
||
| 357 | * Get the preloaded CSS array of the imported library formatted as a comma-separated string. |
||
| 358 | * |
||
| 359 | * @return string the preloaded CSS array of the imported library formatted as a comma-separated string |
||
| 360 | */ |
||
| 361 | public function getPreloadedCssFormatted(): string |
||
| 372 | } |
||
| 373 | |||
| 374 | /** |
||
| 375 | * Get the embed types array formatted as a comma-separated string. |
||
| 376 | * |
||
| 377 | * @return string the embed types array formatted as a comma-separated string |
||
| 378 | */ |
||
| 379 | public function getEmbedTypesFormatted(): string |
||
| 380 | { |
||
| 381 | return implode(',', $this->getEmbedTypes()); |
||
| 382 | } |
||
| 383 | } |
||
| 384 |