Code Duplication    Length = 46-46 lines in 2 locations

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

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