Code Duplication    Length = 46-46 lines in 2 locations

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

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