| Total Complexity | 49 |
| Total Lines | 337 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like EventDemand 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 EventDemand, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 23 | class EventDemand |
||
| 24 | { |
||
| 25 | protected string $displayMode = 'all'; |
||
| 26 | protected string $storagePage = ''; |
||
| 27 | protected ?DateTime $currentDateTime = null; |
||
| 28 | protected string $category = ''; |
||
| 29 | protected bool $includeSubcategories = false; |
||
| 30 | protected string $categoryConjunction = ''; |
||
| 31 | protected int $topEventRestriction = 0; |
||
| 32 | protected string $orderField = ''; |
||
| 33 | protected string $orderFieldAllowed = ''; |
||
| 34 | protected string $orderDirection = ''; |
||
| 35 | protected int $queryLimit = 0; |
||
| 36 | protected string $locationCity = ''; |
||
| 37 | protected string $locationCountry = ''; |
||
| 38 | protected int $year = 0; |
||
| 39 | protected int $month = 0; |
||
| 40 | protected int $day = 0; |
||
| 41 | protected ?SearchDemand $searchDemand = null; |
||
| 42 | protected bool $ignoreEnableFields = false; |
||
| 43 | protected string $timeRestrictionLow = ''; |
||
| 44 | protected string $timeRestrictionHigh = ''; |
||
| 45 | protected bool $includeCurrent = false; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Can be an object (if set by code/property mapper) or a string if set by settings array from plugin |
||
| 49 | * |
||
| 50 | * @var Location|string|null |
||
| 51 | */ |
||
| 52 | protected $location = null; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Can be an object (if set by code/property mapper) or a string if set by settings array from plugin |
||
| 56 | * |
||
| 57 | * @var Speaker|string|null |
||
| 58 | */ |
||
| 59 | protected $speaker = null; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Can be an object (if set by code/property mapper) or a string if set by settings array from plugin |
||
| 63 | * |
||
| 64 | * @var Organisator|string|null |
||
| 65 | */ |
||
| 66 | protected $organisator = null; |
||
| 67 | |||
| 68 | public function getDisplayMode(): string |
||
| 69 | { |
||
| 70 | return $this->displayMode; |
||
| 71 | } |
||
| 72 | |||
| 73 | public function setDisplayMode(string $displayMode): void |
||
| 74 | { |
||
| 75 | $this->displayMode = $displayMode; |
||
| 76 | } |
||
| 77 | |||
| 78 | public function getStoragePage(): string |
||
| 79 | { |
||
| 80 | return $this->storagePage; |
||
| 81 | } |
||
| 82 | |||
| 83 | public function setStoragePage(string $storagePage): void |
||
| 84 | { |
||
| 85 | $this->storagePage = $storagePage; |
||
| 86 | } |
||
| 87 | |||
| 88 | public function setCurrentDateTime(DateTime $currentDateTime): void |
||
| 89 | { |
||
| 90 | $this->currentDateTime = $currentDateTime; |
||
| 91 | } |
||
| 92 | |||
| 93 | public function getCurrentDateTime(): DateTime |
||
| 94 | { |
||
| 95 | return $this->currentDateTime ?? new \DateTime(); |
||
| 96 | } |
||
| 97 | |||
| 98 | public function setCategory(string $category): void |
||
| 99 | { |
||
| 100 | $this->category = $category; |
||
| 101 | } |
||
| 102 | |||
| 103 | public function getCategory(): string |
||
| 104 | { |
||
| 105 | return $this->category; |
||
| 106 | } |
||
| 107 | |||
| 108 | public function getIncludeSubcategories(): bool |
||
| 109 | { |
||
| 110 | return $this->includeSubcategories; |
||
| 111 | } |
||
| 112 | |||
| 113 | public function setIncludeSubcategories(bool $includeSubcategories): void |
||
| 116 | } |
||
| 117 | |||
| 118 | public function getTopEventRestriction(): int |
||
| 119 | { |
||
| 120 | return $this->topEventRestriction; |
||
| 121 | } |
||
| 122 | |||
| 123 | public function setTopEventRestriction(int $topEventRestriction): void |
||
| 124 | { |
||
| 125 | $this->topEventRestriction = $topEventRestriction; |
||
| 126 | } |
||
| 127 | |||
| 128 | public function getOrderDirection(): string |
||
| 129 | { |
||
| 130 | return $this->orderDirection; |
||
| 131 | } |
||
| 132 | |||
| 133 | public function setOrderDirection(string $orderDirection): void |
||
| 134 | { |
||
| 135 | $this->orderDirection = $orderDirection; |
||
| 136 | } |
||
| 137 | |||
| 138 | public function getOrderField(): string |
||
| 139 | { |
||
| 140 | return $this->orderField; |
||
| 141 | } |
||
| 142 | |||
| 143 | public function setOrderField(string $orderField): void |
||
| 144 | { |
||
| 145 | $this->orderField = $orderField; |
||
| 146 | } |
||
| 147 | |||
| 148 | public function getOrderFieldAllowed(): string |
||
| 149 | { |
||
| 150 | return $this->orderFieldAllowed; |
||
| 151 | } |
||
| 152 | |||
| 153 | public function setOrderFieldAllowed(string $orderFieldAllowed): void |
||
| 154 | { |
||
| 155 | $this->orderFieldAllowed = $orderFieldAllowed; |
||
| 156 | } |
||
| 157 | |||
| 158 | public function getQueryLimit(): int |
||
| 159 | { |
||
| 160 | return $this->queryLimit; |
||
| 161 | } |
||
| 162 | |||
| 163 | public function setQueryLimit(int $queryLimit): void |
||
| 164 | { |
||
| 165 | $this->queryLimit = $queryLimit; |
||
| 166 | } |
||
| 167 | |||
| 168 | public function getLocationCity(): string |
||
| 169 | { |
||
| 170 | return $this->locationCity; |
||
| 171 | } |
||
| 172 | |||
| 173 | public function setLocationCity(string $locationCity): void |
||
| 174 | { |
||
| 175 | $this->locationCity = $locationCity; |
||
| 176 | } |
||
| 177 | |||
| 178 | public function getLocationCountry(): string |
||
| 179 | { |
||
| 180 | return $this->locationCountry; |
||
| 181 | } |
||
| 182 | |||
| 183 | public function setLocationCountry(string $locationCountry): void |
||
| 184 | { |
||
| 185 | $this->locationCountry = $locationCountry; |
||
| 186 | } |
||
| 187 | |||
| 188 | public function getYear(): int |
||
| 189 | { |
||
| 190 | return $this->year; |
||
| 191 | } |
||
| 192 | |||
| 193 | public function setYear(int $year): void |
||
| 194 | { |
||
| 195 | $this->year = $year; |
||
| 196 | } |
||
| 197 | |||
| 198 | public function getMonth(): int |
||
| 199 | { |
||
| 200 | return $this->month; |
||
| 201 | } |
||
| 202 | |||
| 203 | public function setMonth(int $month): void |
||
| 204 | { |
||
| 205 | $this->month = $month; |
||
| 206 | } |
||
| 207 | |||
| 208 | public function getDay(): int |
||
| 209 | { |
||
| 210 | return $this->day; |
||
| 211 | } |
||
| 212 | |||
| 213 | public function setDay(int $day): void |
||
| 214 | { |
||
| 215 | $this->day = $day; |
||
| 216 | } |
||
| 217 | |||
| 218 | public function getSearchDemand(): ?SearchDemand |
||
| 219 | { |
||
| 220 | return $this->searchDemand; |
||
| 221 | } |
||
| 222 | |||
| 223 | public function setSearchDemand(?SearchDemand $searchDemand): void |
||
| 224 | { |
||
| 225 | $this->searchDemand = $searchDemand; |
||
| 226 | } |
||
| 227 | |||
| 228 | public function getCategoryConjunction(): string |
||
| 229 | { |
||
| 230 | return $this->categoryConjunction; |
||
| 231 | } |
||
| 232 | |||
| 233 | public function setCategoryConjunction(string $categoryConjunction): void |
||
| 234 | { |
||
| 235 | $this->categoryConjunction = $categoryConjunction; |
||
| 236 | } |
||
| 237 | |||
| 238 | public function getIgnoreEnableFields(): bool |
||
| 241 | } |
||
| 242 | |||
| 243 | public function setIgnoreEnableFields(bool $ignoreEnableFields): void |
||
| 244 | { |
||
| 245 | $this->ignoreEnableFields = $ignoreEnableFields; |
||
| 246 | } |
||
| 247 | |||
| 248 | public function getTimeRestrictionLow(): string |
||
| 249 | { |
||
| 250 | return $this->timeRestrictionLow; |
||
| 251 | } |
||
| 252 | |||
| 253 | public function setTimeRestrictionLow(string $timeRestrictionLow): void |
||
| 254 | { |
||
| 255 | $this->timeRestrictionLow = $timeRestrictionLow; |
||
| 256 | } |
||
| 257 | |||
| 258 | public function getTimeRestrictionHigh(): string |
||
| 259 | { |
||
| 260 | return $this->timeRestrictionHigh; |
||
| 261 | } |
||
| 262 | |||
| 263 | public function setTimeRestrictionHigh(string $timeRestrictionHigh): void |
||
| 264 | { |
||
| 265 | $this->timeRestrictionHigh = $timeRestrictionHigh; |
||
| 266 | } |
||
| 267 | |||
| 268 | public function getIncludeCurrent(): bool |
||
| 269 | { |
||
| 270 | return $this->includeCurrent; |
||
| 271 | } |
||
| 272 | |||
| 273 | public function setIncludeCurrent(bool $includeCurrent): void |
||
| 274 | { |
||
| 275 | $this->includeCurrent = $includeCurrent; |
||
| 276 | } |
||
| 277 | |||
| 278 | /** |
||
| 279 | * @return Location|string|null |
||
| 280 | */ |
||
| 281 | public function getLocation() |
||
| 282 | { |
||
| 283 | return $this->location; |
||
| 284 | } |
||
| 285 | |||
| 286 | /** |
||
| 287 | * @param Location|string|null $location |
||
| 288 | */ |
||
| 289 | public function setLocation($location): void |
||
| 290 | { |
||
| 291 | $this->location = $location; |
||
| 292 | } |
||
| 293 | |||
| 294 | /** |
||
| 295 | * @return Speaker|string|null |
||
| 296 | */ |
||
| 297 | public function getSpeaker() |
||
| 298 | { |
||
| 299 | return $this->speaker; |
||
| 300 | } |
||
| 301 | |||
| 302 | /** |
||
| 303 | * @param Speaker|string|null $speaker |
||
| 304 | */ |
||
| 305 | public function setSpeaker($speaker): void |
||
| 306 | { |
||
| 307 | $this->speaker = $speaker; |
||
| 308 | } |
||
| 309 | |||
| 310 | /** |
||
| 311 | * @return Organisator|string|null |
||
| 312 | */ |
||
| 313 | public function getOrganisator() |
||
| 314 | { |
||
| 315 | return $this->organisator; |
||
| 316 | } |
||
| 317 | |||
| 318 | /** |
||
| 319 | * @param Organisator|string|null $organisator |
||
| 320 | */ |
||
| 321 | public function setOrganisator($organisator): void |
||
| 324 | } |
||
| 325 | |||
| 326 | /** |
||
| 327 | * Creates a new EventDemand object from the given settings. Respects recursive setting for storage page |
||
| 328 | * and extends all PIDs to children if set. |
||
| 329 | * |
||
| 330 | * @param array $settings |
||
| 331 | * @return EventDemand |
||
| 332 | */ |
||
| 333 | public static function createFromSettings(array $settings = []): self |
||
| 360 | } |
||
| 361 | } |
||
| 362 |