Complex classes like OgSeoGenerator 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. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
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 OgSeoGenerator, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 25 | class OgSeoGenerator extends AbstractSeoGenerator |
||
| 26 | { |
||
| 27 | /** |
||
| 28 | * @param string $content |
||
| 29 | * |
||
| 30 | * @return $this |
||
| 31 | */ |
||
| 32 | public function setType($content) |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @return MetaTag |
||
| 39 | */ |
||
| 40 | public function getType() |
||
| 44 | /** |
||
| 45 | * @param string $content |
||
| 46 | * |
||
| 47 | * @return $this |
||
| 48 | */ |
||
| 49 | public function setSiteName($content) |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @return MetaTag |
||
| 56 | */ |
||
| 57 | public function getSiteName() |
||
| 61 | |||
| 62 | /** |
||
| 63 | * @param string $content |
||
| 64 | * |
||
| 65 | * @return $this |
||
| 66 | */ |
||
| 67 | public function setTitle($content) |
||
| 71 | |||
| 72 | /** |
||
| 73 | * @return MetaTag |
||
| 74 | */ |
||
| 75 | public function getTitle() |
||
| 79 | |||
| 80 | /** |
||
| 81 | * @param string $content |
||
| 82 | * |
||
| 83 | * @return $this |
||
| 84 | */ |
||
| 85 | public function setImage($content) |
||
| 89 | |||
| 90 | /** |
||
| 91 | * @return MetaTag |
||
| 92 | */ |
||
| 93 | public function getImage() |
||
| 97 | |||
| 98 | /** |
||
| 99 | * @param string $content |
||
| 100 | * |
||
| 101 | * @return $this |
||
| 102 | */ |
||
| 103 | public function setImageType($content) |
||
| 107 | |||
| 108 | /** |
||
| 109 | * @return MetaTag |
||
| 110 | */ |
||
| 111 | public function getImageType() |
||
| 115 | |||
| 116 | /** |
||
| 117 | * @param string $content |
||
| 118 | * |
||
| 119 | * @return $this |
||
| 120 | */ |
||
| 121 | public function setImageAlt($content) |
||
| 125 | |||
| 126 | /** |
||
| 127 | * @return MetaTag |
||
| 128 | */ |
||
| 129 | public function getImageAlt() |
||
| 133 | |||
| 134 | /** |
||
| 135 | * @param int $content |
||
| 136 | * |
||
| 137 | * @return $this |
||
| 138 | */ |
||
| 139 | public function setImageWidth($content) |
||
| 143 | |||
| 144 | /** |
||
| 145 | * @return MetaTag |
||
| 146 | */ |
||
| 147 | public function getImageWidth() |
||
| 151 | |||
| 152 | /** |
||
| 153 | * @param int $content |
||
| 154 | * |
||
| 155 | * @return $this |
||
| 156 | */ |
||
| 157 | public function setImageHeight($content) |
||
| 161 | |||
| 162 | /** |
||
| 163 | * @return MetaTag |
||
| 164 | */ |
||
| 165 | public function getImageHeight() |
||
| 169 | |||
| 170 | /** |
||
| 171 | * @param string $content |
||
| 172 | * |
||
| 173 | * @return $this |
||
| 174 | */ |
||
| 175 | public function setImageSecureUrl($content) |
||
| 179 | |||
| 180 | /** |
||
| 181 | * @return MetaTag |
||
| 182 | */ |
||
| 183 | public function getImageSecureUrl() |
||
| 187 | |||
| 188 | /** |
||
| 189 | * @param string $content |
||
| 190 | * |
||
| 191 | * @return $this |
||
| 192 | */ |
||
| 193 | public function setVideo($content) |
||
| 197 | |||
| 198 | /** |
||
| 199 | * @return MetaTag |
||
| 200 | */ |
||
| 201 | public function getVideo() |
||
| 205 | |||
| 206 | /** |
||
| 207 | * @param string $content |
||
| 208 | * |
||
| 209 | * @return $this |
||
| 210 | */ |
||
| 211 | public function setVideoType($content) |
||
| 215 | |||
| 216 | /** |
||
| 217 | * @return MetaTag |
||
| 218 | */ |
||
| 219 | public function getVideoType() |
||
| 223 | |||
| 224 | /** |
||
| 225 | * @param int $content |
||
| 226 | * |
||
| 227 | * @return $this |
||
| 228 | */ |
||
| 229 | public function setVideoWidth($content) |
||
| 233 | |||
| 234 | /** |
||
| 235 | * @return MetaTag |
||
| 236 | */ |
||
| 237 | public function getVideoWidth() |
||
| 241 | |||
| 242 | /** |
||
| 243 | * @param int $content |
||
| 244 | * |
||
| 245 | * @return $this |
||
| 246 | */ |
||
| 247 | public function setVideoHeight($content) |
||
| 251 | |||
| 252 | /** |
||
| 253 | * @return MetaTag |
||
| 254 | */ |
||
| 255 | public function getVideoHeight() |
||
| 259 | |||
| 260 | /** |
||
| 261 | * @param string $content |
||
| 262 | * |
||
| 263 | * @return $this |
||
| 264 | */ |
||
| 265 | public function setVideoSecureUrl($content) |
||
| 269 | |||
| 270 | /** |
||
| 271 | * @return MetaTag |
||
| 272 | */ |
||
| 273 | public function getVideoSecureUrl() |
||
| 277 | |||
| 278 | /** |
||
| 279 | * @param string $content |
||
| 280 | * |
||
| 281 | * @return $this |
||
| 282 | */ |
||
| 283 | public function setAudio($content) |
||
| 287 | |||
| 288 | /** |
||
| 289 | * @return MetaTag |
||
| 290 | */ |
||
| 291 | public function getAudio() |
||
| 295 | |||
| 296 | /** |
||
| 297 | * @param string $content |
||
| 298 | * |
||
| 299 | * @return $this |
||
| 300 | */ |
||
| 301 | public function setAudioType($content) |
||
| 305 | |||
| 306 | /** |
||
| 307 | * @return MetaTag |
||
| 308 | */ |
||
| 309 | public function getAudioType() |
||
| 313 | |||
| 314 | /** |
||
| 315 | * @param string $content |
||
| 316 | * |
||
| 317 | * @return $this |
||
| 318 | */ |
||
| 319 | public function setAudioSecureUrl($content) |
||
| 323 | |||
| 324 | /** |
||
| 325 | * @return MetaTag |
||
| 326 | */ |
||
| 327 | public function getAudioSecureUrl() |
||
| 331 | |||
| 332 | /** |
||
| 333 | * @param string $content |
||
| 334 | * |
||
| 335 | * @return $this |
||
| 336 | */ |
||
| 337 | public function setDescription($content) |
||
| 341 | |||
| 342 | /** |
||
| 343 | * @return MetaTag |
||
| 344 | */ |
||
| 345 | public function getDescription() |
||
| 349 | |||
| 350 | /** |
||
| 351 | * @param string $content |
||
| 352 | * |
||
| 353 | * @return $this |
||
| 354 | */ |
||
| 355 | public function setLocale($content) |
||
| 359 | |||
| 360 | /** |
||
| 361 | * @return MetaTag |
||
| 362 | */ |
||
| 363 | public function getLocale() |
||
| 367 | |||
| 368 | /** |
||
| 369 | * @param string[] $locales |
||
| 370 | * |
||
| 371 | * @return $this |
||
| 372 | */ |
||
| 373 | public function setAlternateLocales($locales) |
||
| 377 | |||
| 378 | /** |
||
| 379 | * @return MetaTag |
||
| 380 | */ |
||
| 381 | public function getAlternateLocales() |
||
| 385 | |||
| 386 | /** |
||
| 387 | * @param string $content |
||
| 388 | * |
||
| 389 | * @return $this |
||
| 390 | */ |
||
| 391 | public function setDeterminer($content) |
||
| 395 | |||
| 396 | /** |
||
| 397 | * @return MetaTag |
||
| 398 | */ |
||
| 399 | public function getDeterminer() |
||
| 403 | |||
| 404 | /** |
||
| 405 | * @param string $content |
||
| 406 | * |
||
| 407 | * @return $this |
||
| 408 | */ |
||
| 409 | public function setUrl($content) |
||
| 413 | |||
| 414 | /** |
||
| 415 | * @return MetaTag |
||
| 416 | */ |
||
| 417 | public function getUrl() |
||
| 421 | |||
| 422 | /** |
||
| 423 | * Generate seo tags from given resource. |
||
| 424 | * |
||
| 425 | * @param TitleSeoInterface|DescriptionSeoInterface|ImageSeoInterface $resource |
||
| 426 | * |
||
| 427 | * @return $this |
||
| 428 | */ |
||
| 429 | public function fromResource($resource) |
||
| 501 | |||
| 502 | /** |
||
| 503 | * @param string $type |
||
| 504 | * |
||
| 505 | * @return MetaTag |
||
| 506 | */ |
||
| 507 | public function get($type) |
||
| 511 | |||
| 512 | /** |
||
| 513 | * @param string $type |
||
| 514 | * @param string $value |
||
| 515 | * |
||
| 516 | * @return $this |
||
| 517 | */ |
||
| 518 | public function set($type, $value) |
||
| 527 | } |
||
| 528 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: