| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace PWWEB\Artomator\Commands; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Illuminate\Console\Command; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Illuminate\Support\Composer; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use InfyOm\Generator\Commands\RollbackGeneratorCommand as Base; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use InfyOm\Generator\Generators\Scaffold\ViewGenerator; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use PWWEB\Artomator\Common\CommandData; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use PWWEB\Artomator\Generators\GraphQL\GraphQLInputGenerator; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use PWWEB\Artomator\Generators\GraphQL\GraphQLMutationGenerator; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use PWWEB\Artomator\Generators\GraphQL\GraphQLQueryGenerator; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use PWWEB\Artomator\Generators\GraphQL\GraphQLSubscriptionGenerator; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use PWWEB\Artomator\Generators\GraphQL\GraphQLTypeGenerator; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | class RollbackGeneratorCommand extends Base | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |      * The command Data. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |      * @var CommandData | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     public $commandData; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |      * The console command name. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     protected $name = 'artomator:rollback'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |      * Composer. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |      * @var Composer | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |     public $composer; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |      * Create a new command instance. | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 40 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |     public function __construct() | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |         parent::__construct(); | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |         $this->composer = app()['composer']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |      * Execute the command. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |      * @return void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |     public function handle() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         if (false === in_array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |             $this->argument('type'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |             [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |                 CommandData::$COMMAND_TYPE_API, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |                 CommandData::$COMMAND_TYPE_SCAFFOLD, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |                 CommandData::$COMMAND_TYPE_API_SCAFFOLD, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |                 CommandData::$COMMAND_TYPE_GRAPHQL, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |                 CommandData::$COMMAND_TYPE_GRAPHQL_SCAFFOLD, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |             ] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |             $this->error('invalid rollback type'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         $this->commandData = new CommandData($this, $this->argument('type')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |         $this->commandData->config->mName = $this->commandData->modelName = $this->argument('model'); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |         $this->commandData->config->init($this->commandData, ['tableName', 'prefix', 'plural', 'views']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |         $views = $this->commandData->getOption('views'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |         if (false === empty($views)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |             $views = explode(',', $views); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |             $viewGenerator = new ViewGenerator($this->commandData); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |             $viewGenerator->rollback($views); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |             $this->info('Generating autoload files'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |             $this->composer->dumpOptimized(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |             return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |         $typeGenerator = new GraphQLTypeGenerator($this->commandData); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |         $typeGenerator->rollback(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |         $queryGenerator = new GraphQLQueryGenerator($this->commandData); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |         $queryGenerator->rollback(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |         $inputGenerator = new GraphQLInputGenerator($this->commandData); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |         $inputGenerator->rollback(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |         $mutationGenerator = new GraphQLMutationGenerator($this->commandData); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |         $mutationGenerator->rollback(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |         if (true === config('pwweb.artomator.options.subscription')) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |             $subscriptionGenerator = new GraphQLSubscriptionGenerator($this->commandData); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |             $subscriptionGenerator->rollback(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |         parent::handle(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 105 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 106 |  |  |  | 
            
                        
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountIdthat can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theidproperty of an instance of theAccountclass. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.