Code Duplication    Length = 30-30 lines in 2 locations

UnitOfWork.php 2 locations

@@ 1738-1767 (lines=30) @@
1735
     *
1736
     * @return void
1737
     */
1738
    private function cascadeRefresh($entity, array &$visited)
1739
    {
1740
        $class               = $this->manager->getClassMetadata(get_class($entity));
1741
        $associationMappings = array_filter(
1742
            $class->getAssociationMappings(),
1743
            function ($assoc) {
1744
                return $assoc['isCascadeRefresh'];
1745
            }
1746
        );
1747
        foreach ($associationMappings as $assoc) {
1748
            $relatedEntities = $class->getReflectionProperty($assoc['fieldName'])->getValue($entity);
1749
            switch (true) {
1750
                case ($relatedEntities instanceof ApiCollection):
1751
                    // Unwrap so that foreach() does not initialize
1752
                    $relatedEntities = $relatedEntities->unwrap();
1753
                // break; is commented intentionally!
1754
                case ($relatedEntities instanceof Collection):
1755
                case (is_array($relatedEntities)):
1756
                    foreach ($relatedEntities as $relatedEntity) {
1757
                        $this->doRefresh($relatedEntity, $visited);
1758
                    }
1759
                    break;
1760
                case ($relatedEntities !== null):
1761
                    $this->doRefresh($relatedEntities, $visited);
1762
                    break;
1763
                default:
1764
                    // Do nothing
1765
            }
1766
        }
1767
    }
1768
1769
    /**
1770
     * Cascades a detach operation to associated entities.
@@ 1777-1806 (lines=30) @@
1774
     *
1775
     * @return void
1776
     */
1777
    private function cascadeDetach($entity, array &$visited)
1778
    {
1779
        $class               = $this->manager->getClassMetadata(get_class($entity));
1780
        $associationMappings = array_filter(
1781
            $class->getAssociationMappings(),
1782
            function ($assoc) {
1783
                return $assoc['isCascadeDetach'];
1784
            }
1785
        );
1786
        foreach ($associationMappings as $assoc) {
1787
            $relatedEntities = $class->getReflectionProperty($assoc['fieldName'])->getValue($entity);
1788
            switch (true) {
1789
                case ($relatedEntities instanceof ApiCollection):
1790
                    // Unwrap so that foreach() does not initialize
1791
                    $relatedEntities = $relatedEntities->unwrap();
1792
                // break; is commented intentionally!
1793
                case ($relatedEntities instanceof Collection):
1794
                case (is_array($relatedEntities)):
1795
                    foreach ($relatedEntities as $relatedEntity) {
1796
                        $this->doDetach($relatedEntity, $visited);
1797
                    }
1798
                    break;
1799
                case ($relatedEntities !== null):
1800
                    $this->doDetach($relatedEntities, $visited);
1801
                    break;
1802
                default:
1803
                    // Do nothing
1804
            }
1805
        }
1806
    }
1807
1808
    /**
1809
     * Cascades a merge operation to associated entities.