| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | declare(strict_types=1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | namespace App\User\Console; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use App\User\User; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use InvalidArgumentException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 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\Question\ConfirmationQuestion; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use Symfony\Component\Console\Style\SymfonyStyle; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use Throwable; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use Yiisoft\Rbac\ItemsStorageInterface; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use Yiisoft\Rbac\Manager; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | use Yiisoft\Rbac\Role; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | use Yiisoft\Yii\Console\ExitCode; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | use Yiisoft\Yii\Cycle\Command\CycleDependencyProxy; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | final class AssignRoleCommand extends Command | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     protected static $defaultName = 'user/assignRole'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     public function __construct( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |         private CycleDependencyProxy $promise, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |         private Manager $manager, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |         private ItemsStorageInterface $itemsStorage | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |         parent::__construct(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     public function configure(): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         $this | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |             ->setDescription('Assign RBAC role to given user') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |             ->setHelp('This command allows you to assign RBAC role to user') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |             ->addArgument('role', InputArgument::REQUIRED, 'RBAC role') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |             ->addArgument('userId', InputArgument::REQUIRED, 'User id'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |     protected function execute(InputInterface $input, OutputInterface $output): int | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |         $io = new SymfonyStyle($input, $output); | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |         $roleName = $input->getArgument('role'); | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |         $userId = $input->getArgument('userId'); | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |         try { | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |             $orm = $this->promise->getORM(); | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |             $userRepo = $orm->getRepository(User::class); | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |             /** @var User|null $user */ | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |             $user = $userRepo->findByPK($userId); | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |             if (null === $user) { | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |                 throw new InvalidArgumentException('Can\'t find user'); | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |             } | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |             if (null === $user->getId()) { | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |                 throw new InvalidArgumentException('User Id is NULL'); | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |             } | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |             $role = $this->itemsStorage->getRole($roleName); | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  |             if (null === $role) { | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  |                 $helper = $this->getHelper('question'); | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  |                 $question = new ConfirmationQuestion('Role doesn\'t exist. Create new one? ', false); | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 68 |  |  |                 if (!$helper->ask($input, $output, $question)) { | 
            
                                                                        
                            
            
                                    
            
            
                | 69 |  |  |                     return ExitCode::OK; | 
            
                                                                        
                            
            
                                    
            
            
                | 70 |  |  |                 } | 
            
                                                                        
                            
            
                                    
            
            
                | 71 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 72 |  |  |                 $role = new Role($roleName); | 
            
                                                                        
                            
            
                                    
            
            
                | 73 |  |  |                 $this->manager->addRole($role); | 
            
                                                                        
                            
            
                                    
            
            
                | 74 |  |  |             } | 
            
                                                                        
                            
            
                                    
            
            
                | 75 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 76 |  |  |             $this->manager->assign($roleName, $userId); | 
            
                                                                        
                            
            
                                    
            
            
                | 77 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 78 |  |  |             $io->success('Role was assigned to given user'); | 
            
                                                                        
                            
            
                                    
            
            
                | 79 |  |  |         } catch (Throwable $t) { | 
            
                                                                        
                            
            
                                    
            
            
                | 80 |  |  |             $io->error($t->getMessage()); | 
            
                                                                        
                            
            
                                    
            
            
                | 81 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 82 |  |  |             return $t->getCode() ?: ExitCode::UNSPECIFIED_ERROR; | 
            
                                                                        
                            
            
                                    
            
            
                | 83 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 84 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 85 |  |  |         return ExitCode::OK; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 87 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 88 |  |  |  | 
            
                        
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