Code Duplication    Length = 47-47 lines in 2 locations

eZ/Publish/Core/REST/Server/Controller/User.php 2 locations

@@ 719-765 (lines=47) @@
716
     *
717
     * @return \eZ\Publish\Core\REST\Server\Values\UserGroupList|\eZ\Publish\Core\REST\Server\Values\UserGroupRefList
718
     */
719
    public function loadSubUserGroups($groupPath, Request $request)
720
    {
721
        $offset = $request->query->has('offset') ? (int)$request->query->get('offset') : 0;
722
        $limit = $request->query->has('limit') ? (int)$request->query->get('limit') : 25;
723
724
        $userGroupLocation = $this->locationService->loadLocation(
725
            $this->extractLocationIdFromPath($groupPath)
726
        );
727
728
        $userGroup = $this->userService->loadUserGroup(
729
            $userGroupLocation->contentId
730
        );
731
732
        $subGroups = $this->userService->loadSubUserGroups(
733
            $userGroup,
734
            $offset >= 0 ? $offset : 0,
735
            $limit >= 0 ? $limit : 25,
736
            Language::ALL
737
        );
738
739
        $restUserGroups = [];
740
        foreach ($subGroups as $subGroup) {
741
            $subGroupContentInfo = $subGroup->getVersionInfo()->getContentInfo();
742
            $subGroupLocation = $this->locationService->loadLocation($subGroupContentInfo->mainLocationId);
743
            $contentType = $this->contentTypeService->loadContentType($subGroupContentInfo->contentTypeId);
744
745
            $restUserGroups[] = new Values\RestUserGroup(
746
                $subGroup,
747
                $contentType,
748
                $subGroupContentInfo,
749
                $subGroupLocation,
750
                $this->contentService->loadRelations($subGroup->getVersionInfo())
751
            );
752
        }
753
754
        if ($this->getMediaType($request) === 'application/vnd.ez.api.usergrouplist') {
755
            return new Values\CachedValue(
756
                new Values\UserGroupList($restUserGroups, $request->getPathInfo()),
757
                ['locationId' => $userGroupLocation->id]
758
            );
759
        }
760
761
        return new Values\CachedValue(
762
            new Values\UserGroupRefList($restUserGroups, $request->getPathInfo()),
763
            ['locationId' => $userGroupLocation->id]
764
        );
765
    }
766
767
    /**
768
     * Returns a list of user groups the user belongs to.
@@ 817-863 (lines=47) @@
814
     *
815
     * @return \eZ\Publish\Core\REST\Server\Values\UserList|\eZ\Publish\Core\REST\Server\Values\UserRefList
816
     */
817
    public function loadUsersFromGroup($groupPath, Request $request)
818
    {
819
        $userGroupLocation = $this->locationService->loadLocation(
820
            $this->extractLocationIdFromPath($groupPath)
821
        );
822
823
        $userGroup = $this->userService->loadUserGroup(
824
            $userGroupLocation->contentId
825
        );
826
827
        $offset = $request->query->has('offset') ? (int)$request->query->get('offset') : 0;
828
        $limit = $request->query->has('limit') ? (int)$request->query->get('limit') : 25;
829
830
        $users = $this->userService->loadUsersOfUserGroup(
831
            $userGroup,
832
            $offset >= 0 ? $offset : 0,
833
            $limit >= 0 ? $limit : 25,
834
            Language::ALL
835
        );
836
837
        $restUsers = [];
838
        foreach ($users as $user) {
839
            $userContentInfo = $user->getVersionInfo()->getContentInfo();
840
            $userLocation = $this->locationService->loadLocation($userContentInfo->mainLocationId);
841
            $contentType = $this->contentTypeService->loadContentType($userContentInfo->contentTypeId);
842
843
            $restUsers[] = new Values\RestUser(
844
                $user,
845
                $contentType,
846
                $userContentInfo,
847
                $userLocation,
848
                $this->contentService->loadRelations($user->getVersionInfo())
849
            );
850
        }
851
852
        if ($this->getMediaType($request) === 'application/vnd.ez.api.userlist') {
853
            return new Values\CachedValue(
854
                new Values\UserList($restUsers, $request->getPathInfo()),
855
                ['locationId' => $userGroupLocation->id]
856
            );
857
        }
858
859
        return new Values\CachedValue(
860
            new Values\UserRefList($restUsers, $request->getPathInfo()),
861
            ['locationId' => $userGroupLocation->id]
862
        );
863
    }
864
865
    /**
866
     * Unassigns the user from a user group.