File tree Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change 1919use  CodeIgniter \Shield \Entities \User ;
2020use  CodeIgniter \Shield \Entities \UserIdentity ;
2121use  CodeIgniter \Shield \Exceptions \InvalidArgumentException ;
22+ use  CodeIgniter \Shield \Exceptions \LogicException ;
2223use  CodeIgniter \Shield \Exceptions \ValidationException ;
2324use  Faker \Generator ;
2425
@@ -164,7 +165,9 @@ public function addToDefaultGroup(User $user): void
164165
165166    public  function  fake (Generator $ fakerUser 
166167    {
167-         return  new  User ([
168+         $ this checkReturnType ();
169+ 
170+         return  new  $ this returnType ([
168171            'username '  => $ fakerunique ()->userName (),
169172            'active '    => true ,
170173        ]);
@@ -226,7 +229,9 @@ public function findByCredentials(array $credentials): ?User
226229            $ password_hash$ data'password_hash ' ];
227230            unset($ data'password_hash ' ]);
228231
229-             $ usernew  User ($ data
232+             $ this checkReturnType ();
233+ 
234+             $ usernew  $ this returnType ($ data
230235            $ useremail          = $ email
231236            $ userpassword_hash  = $ password_hash
232237            $ usersyncOriginal ();
@@ -383,4 +388,11 @@ public function updateActiveDate(User $user): void
383388            ->where ('id ' , $ userid )
384389            ->update ();
385390    }
391+ 
392+     private  function  checkReturnType (): void 
393+     {
394+         if  (! is_a ($ this returnType , User::class, true )) {
395+             throw  new  LogicException ('Return type must be a subclass of  '  . User::class);
396+         }
397+     }
386398}
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments