Code Duplication    Length = 20-20 lines in 3 locations

eZ/Publish/Core/Repository/LocationService.php 3 locations

@@ 131-150 (lines=20) @@
128
129
        // Check read access to whole source subtree
130
        $contentReadCriterion = $this->permissionCriterionResolver->getPermissionsCriterion('content', 'read');
131
        if ($contentReadCriterion === false) {
132
            throw new UnauthorizedException('content', 'read');
133
        } elseif ($contentReadCriterion !== true) {
134
            // Query if there are any content in subtree current user don't have access to
135
            $query = new Query(
136
                [
137
                    'limit' => 0,
138
                    'filter' => new CriterionLogicalAnd(
139
                        [
140
                            new CriterionSubtree($loadedSubtree->pathString),
141
                            new CriterionLogicalNot($contentReadCriterion),
142
                        ]
143
                    ),
144
                ]
145
            );
146
            $result = $this->repository->getSearchService()->findContent($query, [], false);
147
            if ($result->totalCount > 0) {
148
                throw new UnauthorizedException('content', 'read');
149
            }
150
        }
151
152
        $this->repository->beginTransaction();
153
        try {
@@ 685-704 (lines=20) @@
682
         * @var bool|\eZ\Publish\API\Repository\Values\Content\Query\Criterion
683
         */
684
        $contentReadCriterion = $this->permissionCriterionResolver->getPermissionsCriterion('content', 'read');
685
        if ($contentReadCriterion === false) {
686
            throw new UnauthorizedException('content', 'read');
687
        } elseif ($contentReadCriterion !== true) {
688
            // Query if there are any content in subtree current user don't have access to
689
            $query = new Query(
690
                [
691
                    'limit' => 0,
692
                    'filter' => new CriterionLogicalAnd(
693
                        [
694
                            new CriterionSubtree($location->pathString),
695
                            new CriterionLogicalNot($contentReadCriterion),
696
                        ]
697
                    ),
698
                ]
699
            );
700
            $result = $this->repository->getSearchService()->findContent($query, [], false);
701
            if ($result->totalCount > 0) {
702
                throw new UnauthorizedException('content', 'read');
703
            }
704
        }
705
706
        if (strpos($newParentLocation->pathString, $location->pathString) === 0) {
707
            throw new InvalidArgumentException(
@@ 762-781 (lines=20) @@
759
760
        // Check remove access to descendants
761
        $contentReadCriterion = $this->permissionCriterionResolver->getPermissionsCriterion('content', 'remove');
762
        if ($contentReadCriterion === false) {
763
            throw new UnauthorizedException('content', 'remove');
764
        } elseif ($contentReadCriterion !== true) {
765
            // Query if there are any content in subtree current user don't have access to
766
            $query = new Query(
767
                [
768
                    'limit' => 0,
769
                    'filter' => new CriterionLogicalAnd(
770
                        [
771
                            new CriterionSubtree($location->pathString),
772
                            new CriterionLogicalNot($contentReadCriterion),
773
                        ]
774
                    ),
775
                ]
776
            );
777
            $result = $this->repository->getSearchService()->findContent($query, [], false);
778
            if ($result->totalCount > 0) {
779
                throw new UnauthorizedException('content', 'remove');
780
            }
781
        }
782
783
        $this->repository->beginTransaction();
784
        try {