Code Duplication    Length = 30-30 lines in 2 locations

UnitOfWork.php 2 locations

@@ 1704-1733 (lines=30) @@
1701
     *
1702
     * @return void
1703
     */
1704
    private function cascadeRefresh($entity, array &$visited)
1705
    {
1706
        $class               = $this->manager->getClassMetadata(get_class($entity));
1707
        $associationMappings = array_filter(
1708
            $class->getAssociationMappings(),
1709
            function ($assoc) {
1710
                return $assoc['isCascadeRefresh'];
1711
            }
1712
        );
1713
        foreach ($associationMappings as $assoc) {
1714
            $relatedEntities = $class->getReflectionProperty($assoc['fieldName'])->getValue($entity);
1715
            switch (true) {
1716
                case ($relatedEntities instanceof ApiCollection):
1717
                    // Unwrap so that foreach() does not initialize
1718
                    $relatedEntities = $relatedEntities->unwrap();
1719
                // break; is commented intentionally!
1720
                case ($relatedEntities instanceof Collection):
1721
                case (is_array($relatedEntities)):
1722
                    foreach ($relatedEntities as $relatedEntity) {
1723
                        $this->doRefresh($relatedEntity, $visited);
1724
                    }
1725
                    break;
1726
                case ($relatedEntities !== null):
1727
                    $this->doRefresh($relatedEntities, $visited);
1728
                    break;
1729
                default:
1730
                    // Do nothing
1731
            }
1732
        }
1733
    }
1734
1735
    /**
1736
     * Cascades a detach operation to associated entities.
@@ 1743-1772 (lines=30) @@
1740
     *
1741
     * @return void
1742
     */
1743
    private function cascadeDetach($entity, array &$visited)
1744
    {
1745
        $class               = $this->manager->getClassMetadata(get_class($entity));
1746
        $associationMappings = array_filter(
1747
            $class->getAssociationMappings(),
1748
            function ($assoc) {
1749
                return $assoc['isCascadeDetach'];
1750
            }
1751
        );
1752
        foreach ($associationMappings as $assoc) {
1753
            $relatedEntities = $class->getReflectionProperty($assoc['fieldName'])->getValue($entity);
1754
            switch (true) {
1755
                case ($relatedEntities instanceof ApiCollection):
1756
                    // Unwrap so that foreach() does not initialize
1757
                    $relatedEntities = $relatedEntities->unwrap();
1758
                // break; is commented intentionally!
1759
                case ($relatedEntities instanceof Collection):
1760
                case (is_array($relatedEntities)):
1761
                    foreach ($relatedEntities as $relatedEntity) {
1762
                        $this->doDetach($relatedEntity, $visited);
1763
                    }
1764
                    break;
1765
                case ($relatedEntities !== null):
1766
                    $this->doDetach($relatedEntities, $visited);
1767
                    break;
1768
                default:
1769
                    // Do nothing
1770
            }
1771
        }
1772
    }
1773
1774
    /**
1775
     * Cascades a merge operation to associated entities.