Code Duplication    Length = 46-46 lines in 2 locations

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

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