Code Duplication    Length = 30-30 lines in 2 locations

UnitOfWork.php 2 locations

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