Code Duplication    Length = 30-30 lines in 2 locations

UnitOfWork.php 2 locations

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