| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | declare(strict_types=1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | namespace App\User\Console; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use App\Auth\Form\SignupForm; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use LogicException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Symfony\Component\Console\Command\Command; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use Symfony\Component\Console\Input\InputArgument; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use Symfony\Component\Console\Input\InputInterface; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use Symfony\Component\Console\Output\OutputInterface; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use Symfony\Component\Console\Style\SymfonyStyle; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use Throwable; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use Yiisoft\FormModel\FormHydrator; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use Yiisoft\Rbac\Manager; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use Yiisoft\Yii\Console\ExitCode; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | final class CreateCommand extends Command | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     protected static $defaultName = 'user/create'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     public function __construct( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |         private readonly SignupForm $signupForm, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |         private readonly Manager $manager, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |         private readonly FormHydrator $formHydrator | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |         parent::__construct(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     protected function configure(): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |         $this | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |             ->setDescription('Creates a user') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |             ->setHelp('This command allows you to create a user') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |             ->addArgument('login', InputArgument::REQUIRED, 'Login') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |             ->addArgument('password', InputArgument::REQUIRED, 'Password') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |             ->addArgument('isAdmin', InputArgument::OPTIONAL, 'Create user as admin'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |     protected function execute(InputInterface $input, OutputInterface $output): int | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |         $io = new SymfonyStyle($input, $output); | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |         $login = (string) $input->getArgument('login'); | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |         $password = (string) $input->getArgument('password'); | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |         $isAdmin = (bool) $input->getArgument('isAdmin'); | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |         try { | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |             $this->formHydrator->populate(model: $this->signupForm, data: [ | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |                 'login' => $login, | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |                 'password' => $password, | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |                 'passwordVerify' => $password, | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |             ], scope: ''); | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |             $user = $this->signupForm->signup(); | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |         } catch (Throwable $t) { | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |             $io->error($t->getMessage() . ' ' . $t->getFile() . ' ' . $t->getLine()); | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |             return $t->getCode() ?: ExitCode::UNSPECIFIED_ERROR; | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |         if ($user === false) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |             $errors = $this->signupForm->getValidationResult()?->getErrorMessagesIndexedByProperty(); | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |             array_walk($errors, fn($error, $attribute) => $io->error("$attribute: " . implode("\n", (array) $error))); | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |             return ExitCode::DATAERR; | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  |         if ($isAdmin) { | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  |             $userId = $user->getId(); | 
            
                                                                        
                            
            
                                    
            
            
                | 68 |  |  |             if ($userId === null) { | 
            
                                                                        
                            
            
                                    
            
            
                | 69 |  |  |                 throw new LogicException('User Id is NULL'); | 
            
                                                                        
                            
            
                                    
            
            
                | 70 |  |  |             } | 
            
                                                                        
                            
            
                                    
            
            
                | 71 |  |  |             $this->manager->assign('admin', $userId); | 
            
                                                                        
                            
            
                                    
            
            
                | 72 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 73 |  |  |         $io->success('User created'); | 
            
                                                                        
                            
            
                                    
            
            
                | 74 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 75 |  |  |         return ExitCode::OK; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 77 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 78 |  |  |  | 
            
                        
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths