Code Duplication    Length = 46-46 lines in 2 locations

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

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