Code Duplication    Length = 15-20 lines in 2 locations

src/Query.php 2 locations

@@ 320-339 (lines=20) @@
317
            } elseif (Relationship::HAS_ONE == $type) {
318
                $relationships = $this->fetchRelationships($relationModelClass, $ids[$k], $property->getForeignKey(), false);
319
320
                foreach ($ids[$k] as $j => $id) {
321
                    if (isset($relationships[$id])) {
322
                        $models[$j]->setRelation($k, $relationships[$id]);
323
                        // older style properties do not support this type of hydration
324
                        if (!$property->isPersisted()) {
325
                            $models[$j]->hydrateValue($k, $relationships[$id]);
326
                        }
327
                    } else {
328
                        // when using has one eager loading we must
329
                        // explicitly mark the relationship as null
330
                        // for models not found during eager loading
331
                        // or else it will trigger another DB call
332
                        $models[$j]->clearRelation($k);
333
334
                        // older style properties do not support this type of hydration
335
                        if (!$property->isPersisted()) {
336
                            $models[$j]->hydrateValue($k, null);
337
                        }
338
                    }
339
                }
340
            } elseif (Relationship::HAS_MANY == $type) {
341
                $relationships = $this->fetchRelationships($relationModelClass, $ids[$k], $property->getForeignKey(), true);
342
@@ 343-357 (lines=15) @@
340
            } elseif (Relationship::HAS_MANY == $type) {
341
                $relationships = $this->fetchRelationships($relationModelClass, $ids[$k], $property->getForeignKey(), true);
342
343
                foreach ($ids[$k] as $j => $id) {
344
                    if (isset($relationships[$id])) {
345
                        $models[$j]->setRelationCollection($k, $relationships[$id]);
346
                        // older style properties do not support this type of hydration
347
                        if (!$property->isPersisted()) {
348
                            $models[$j]->hydrateValue($k, $relationships[$id]);
349
                        }
350
                    } else {
351
                        $models[$j]->setRelationCollection($k, []);
352
                        // older style properties do not support this type of hydration
353
                        if (!$property->isPersisted()) {
354
                            $models[$j]->hydrateValue($k, []);
355
                        }
356
                    }
357
                }
358
            }
359
        }
360