Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php | ||
| 35 | class PageManager extends TrackingManager | ||
| 36 | { | ||
| 37 | /** @var StaticPageView[] A place to store a reference to static PageViews with titles. */ | ||
| 38 | private $staticPages; | ||
| 39 | /** @var RepeaterPageView[] A place to store a reference to repeater PageViews with titles. */ | ||
| 40 | private $repeaterPages; | ||
| 41 | private $configuration; | ||
| 42 | private $collectionManager; | ||
| 43 | private $dataManager; | ||
| 44 | private $eventDispatcher; | ||
| 45 | private $logger; | ||
| 46 | |||
| 47 | /** | ||
| 48 | * PageManager constructor. | ||
| 49 | */ | ||
| 50 | 20 | public function __construct( | |
| 70 | |||
| 71 | /** | ||
| 72 |      * {@inheritdoc} | ||
| 73 | */ | ||
| 74 | 7 | public function compileManager() | |
| 78 | |||
| 79 | /** | ||
| 80 | * Go through all of the PageView directories and create a respective PageView for each and classify them by type. | ||
| 81 | * | ||
| 82 | * @param string[] $pageViewFolders | ||
| 83 | * | ||
| 84 | * @since 0.1.0 | ||
| 85 | */ | ||
| 86 | 19 | public function parsePageViews(array $pageViewFolders) | |
| 112 | |||
| 113 | /** | ||
| 114 | * Get all of the PageViews in an associative array with PageView types as the keys. | ||
| 115 | * | ||
| 116 | * @since 0.1.1 | ||
| 117 | * | ||
| 118 | * @return BasePageView[][] | ||
| 119 | */ | ||
| 120 | 1 | public function &getPageViews() | |
| 124 | |||
| 125 | /** | ||
| 126 | * Get all of the PageViews in flat array. | ||
| 127 | * | ||
| 128 | * @since 0.1.1 | ||
| 129 | * | ||
| 130 | * @return BasePageView[] | ||
| 131 | */ | ||
| 132 | 17 | public function &getPageViewsFlattened() | |
| 136 | |||
| 137 | /** | ||
| 138 | * Get the static PageViews tracked by this manager indexed by their title. | ||
| 139 | * | ||
| 140 | * @since 0.1.0 | ||
| 141 | * | ||
| 142 | * @return StaticPageView[] | ||
| 143 | */ | ||
| 144 | 1 | public function getStaticPageViews() | |
| 148 | |||
| 149 | /** | ||
| 150 | * Get the jailed version of the static PageViews indexed by their title. | ||
| 151 | * | ||
| 152 | * @since 0.1.0 | ||
| 153 | * | ||
| 154 | * @return JailedDocument[] | ||
| 155 | */ | ||
| 156 | 13 | public function getJailedStaticPageViews() | |
| 167 | |||
| 168 | /** | ||
| 169 | * Get the jailed version of repeater PageViews indexed by their title. | ||
| 170 | */ | ||
| 171 | 12 | public function getJailedRepeaterPageViews() | |
| 182 | |||
| 183 | /** | ||
| 184 | * Add a PageView for this PageManager to track. | ||
| 185 | * | ||
| 186 | * @param BasePageView|StaticPageView|DynamicPageView|RepeaterPageView $pageView | ||
| 187 | * | ||
| 188 | * @throws \LogicException When a PageView is treated as the wrong type | ||
| 189 | * @throws CollectionNotFoundException When the collection specified in a Dynamic PageView isn't found | ||
| 190 | * @throws \Exception The permalink could not be built correctly | ||
| 191 | * | ||
| 192 | * @since 0.2.0 | ||
| 193 | */ | ||
| 194 | 19 | public function trackNewPageView(BasePageView $pageView) | |
| 195 |     { | ||
| 196 | 19 | $namespace = $pageView->getType(); | |
| 197 | |||
| 198 | switch ($namespace) | ||
| 199 |         { | ||
| 200 | 19 | case BasePageView::STATIC_TYPE: | |
| 201 | 12 | $this->handleTrackableStaticPageView($pageView); | |
| 202 | 12 | break; | |
| 203 | |||
| 204 | 7 | case BasePageView::DYNAMIC_TYPE: | |
| 205 | 4 | $this->handleTrackableDynamicPageView($pageView); | |
| 206 | 3 | break; | |
| 207 | |||
| 208 | 3 | case BasePageView::REPEATER_TYPE: | |
| 209 | 3 | $this->handleTrackableRepeaterPageView($pageView); | |
| 210 | 3 | break; | |
| 211 | |||
| 212 | default: | ||
| 213 | break; | ||
| 214 | } | ||
| 215 | |||
| 216 | 18 | $event = new PageViewAdded($pageView); | |
| 217 | 18 | $this->eventDispatcher->dispatch(PageViewAdded::NAME, $event); | |
| 218 | |||
| 219 | 18 | $this->addObjectToTracker($pageView, $namespace); | |
| 220 | 18 | } | |
| 221 | |||
| 222 | /** | ||
| 223 | * Add a new ContentItem to the respective parent PageView of the ContentItem. | ||
| 224 | * | ||
| 225 | * @param ContentItem $contentItem | ||
| 226 | * | ||
| 227 | * @since 0.1.0 | ||
| 228 | */ | ||
| 229 | 1 | public function trackNewContentItem(&$contentItem) | |
| 234 | |||
| 235 | /** | ||
| 236 |      * {@inheritdoc} | ||
| 237 | */ | ||
| 238 | 18 | protected function &handleTrackableItem(File $filePath, array $options = []) | |
| 248 | |||
| 249 | /** | ||
| 250 | * Handle special behavior and treatment for static PageViews while we're iterating through them. | ||
| 251 | * | ||
| 252 | * @param StaticPageView $pageView | ||
| 253 | * | ||
| 254 | * @since 0.1.0 | ||
| 255 | */ | ||
| 256 | 12 | View Code Duplication | private function handleTrackableStaticPageView(&$pageView) | 
| 269 | |||
| 270 | /** | ||
| 271 | * Handle special behavior and treatment for dynamic PageViews while we're iterating through them. | ||
| 272 | * | ||
| 273 | * @param DynamicPageView $pageView | ||
| 274 | * | ||
| 275 | * @since 0.1.0 | ||
| 276 | * | ||
| 277 | * @throws \LogicException An invalid PageView has been given as a Dynamic PageView | ||
| 278 | * @throws CollectionNotFoundException When a collection or dataset specified in a Dynamic PageView doesn't exist | ||
| 279 | * @throws \Exception When the permalink for the given PageView hasn't been set | ||
| 280 | */ | ||
| 281 | 4 | private function handleTrackableDynamicPageView(&$pageView) | |
| 322 | |||
| 323 | /** | ||
| 324 | * Handle special behavior and treatment for repeater PageViews while we're iterating through them. | ||
| 325 | * | ||
| 326 | * @param RepeaterPageView $pageView | ||
| 327 | * | ||
| 328 | * @since 0.2.0 | ||
| 329 | */ | ||
| 330 | 3 | View Code Duplication | private function handleTrackableRepeaterPageView(&$pageView) | 
| 344 | } | ||
| 345 | 
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: