| Total Complexity | 52 |
| Total Lines | 223 |
| Duplicated Lines | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 0 |
Complex classes like BaseCommand often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use BaseCommand, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 22 | class BaseCommand extends Base |
||
| 23 | { |
||
| 24 | /** |
||
| 25 | * Handle. |
||
| 26 | * |
||
| 27 | * @return void |
||
| 28 | */ |
||
| 29 | public function handle() |
||
| 30 | { |
||
| 31 | parent::handle(); |
||
| 32 | $this->commandData->config->prepareGraphQLNames($this->option('gqlName')); |
||
| 33 | $this->commandData = $this->commandData->config->loadDynamicGraphQLVariables($this->commandData); |
||
| 34 | } |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Generate Common Items. |
||
| 38 | * |
||
| 39 | * @return void |
||
| 40 | */ |
||
| 41 | public function generateCommonItems() |
||
| 42 | { |
||
| 43 | parent::generateCommonItems(); |
||
| 44 | |||
| 45 | if (false === $this->isSkip('repository') && true === $this->commandData->getOption('repositoryPattern')) { |
||
| 46 | $contractGenerator = new ContractGenerator($this->commandData); |
||
| 47 | $contractGenerator->generate(); |
||
| 48 | } |
||
| 49 | } |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Generate GraphQL Items. |
||
| 53 | * |
||
| 54 | * @return void |
||
| 55 | */ |
||
| 56 | public function generateGraphQLItems() |
||
| 57 | { |
||
| 58 | if (false === ($this->isSkip('queries') or $this->isSkip('graphql_query'))) { |
||
| 59 | $queryGenerator = new GraphQLQueryGenerator($this->commandData); |
||
| 60 | $queryGenerator->generate(); |
||
| 61 | } |
||
| 62 | |||
| 63 | if (false === ($this->isSkip('types') or $this->isSkip('graphql_types'))) { |
||
| 64 | $typeGenerator = new GraphQLTypeGenerator($this->commandData); |
||
| 65 | $typeGenerator->generate(); |
||
| 66 | } |
||
| 67 | |||
| 68 | if (false === ($this->isSkip('mutations') or $this->isSkip('graphql_mutations'))) { |
||
| 69 | $mutationGenerator = new GraphQLMutationGenerator($this->commandData); |
||
| 70 | $mutationGenerator->generate(); |
||
| 71 | } |
||
| 72 | |||
| 73 | if (false === ($this->isSkip('inputs') or $this->isSkip('graphql_inputs'))) { |
||
| 74 | $mutationGenerator = new GraphQLInputGenerator($this->commandData); |
||
| 75 | $mutationGenerator->generate(); |
||
| 76 | } |
||
| 77 | |||
| 78 | if ((false === ($this->isSkip('subscription') or $this->isSkip('graphql_subscription'))) and config('pwweb.artomator.options.subscription')) { |
||
| 79 | $subscriptionGenerator = new GraphQLSubscriptionGenerator($this->commandData); |
||
| 80 | $subscriptionGenerator->generate(); |
||
| 81 | } |
||
| 82 | } |
||
| 83 | |||
| 84 | /** |
||
| 85 | * Generate Scaffold Items. |
||
| 86 | * |
||
| 87 | * @return void |
||
| 88 | */ |
||
| 89 | public function generateScaffoldItems() |
||
| 90 | { |
||
| 91 | if (false === $this->isSkip('requests') and false === $this->isSkip('scaffold_requests')) { |
||
| 92 | $requestGenerator = new RequestGenerator($this->commandData); |
||
| 93 | $requestGenerator->generate(); |
||
| 94 | } |
||
| 95 | |||
| 96 | if (false === $this->isSkip('controllers') and false === $this->isSkip('scaffold_controller')) { |
||
| 97 | $controllerGenerator = new ControllerGenerator($this->commandData); |
||
| 98 | $controllerGenerator->generate(); |
||
| 99 | } |
||
| 100 | |||
| 101 | if (false === $this->isSkip('views') and false === $this->commandData->getOption('vue')) { |
||
| 102 | $viewGenerator = new ViewGenerator($this->commandData); |
||
| 103 | $viewGenerator->generate(); |
||
| 104 | } |
||
| 105 | |||
| 106 | if (false === $this->isSkip('views') and true === $this->commandData->getOption('vue')) { |
||
| 107 | $vueGenerator = new VueGenerator($this->commandData); |
||
| 108 | $vueGenerator->generate(); |
||
| 109 | } |
||
| 110 | |||
| 111 | if (false === $this->isSkip('routes') and false === $this->isSkip('scaffold_routes')) { |
||
| 112 | $routeGenerator = new RoutesGenerator($this->commandData); |
||
| 113 | $routeGenerator->generate(); |
||
| 114 | } |
||
| 115 | |||
| 116 | if (false === $this->isSkip('menu') and $this->commandData->config->getAddOn('menu.enabled')) { |
||
| 117 | $menuGenerator = new MenuGenerator($this->commandData); |
||
| 118 | $menuGenerator->generate(); |
||
| 119 | } |
||
| 120 | } |
||
| 121 | |||
| 122 | /** |
||
| 123 | * Get the console command options. |
||
| 124 | * |
||
| 125 | * @return array |
||
| 126 | */ |
||
| 127 | public function getOptions() |
||
| 128 | { |
||
| 129 | return array_merge( |
||
| 130 | parent::getOptions(), |
||
| 131 | [ |
||
| 132 | ['gqlName', null, InputOption::VALUE_REQUIRED, 'Override the name used in the GraphQL schema file'], |
||
| 133 | ['vue', null, InputOption::VALUE_NONE, 'Generate Vuejs views rather than blade views'], |
||
| 134 | ] |
||
| 135 | ); |
||
| 136 | } |
||
| 137 | |||
| 138 | /** |
||
| 139 | * Perform the Post Generator Actions. |
||
| 140 | * |
||
| 141 | * @param bool $runMigration Boolean flag to run migrations. |
||
| 142 | * |
||
| 143 | * @return void |
||
| 144 | */ |
||
| 145 | public function performPostActions($runMigration = false) |
||
| 146 | { |
||
| 147 | if (true === $this->commandData->getOption('save')) { |
||
| 148 | $this->saveSchemaFile(); |
||
| 149 | } |
||
| 150 | |||
| 151 | if (true === $runMigration) { |
||
| 152 | if (true === $this->commandData->getOption('forceMigrate')) { |
||
| 153 | $this->runMigration(); |
||
| 154 | } elseif (false === $this->commandData->getOption('fromTable') && false === $this->isSkip('migration')) { |
||
| 155 | $requestFromConsole = ('cli' === php_sapi_name()) ? true : false; |
||
| 156 | if (true === $this->commandData->getOption('jsonFromGUI') && true === $requestFromConsole) { |
||
| 157 | $this->runMigration(); |
||
| 158 | } elseif (true === $requestFromConsole && true === $this->confirm("\nDo you want to migrate database? [y|N]", false)) { |
||
| 159 | $this->runMigration(); |
||
| 160 | } |
||
| 161 | } |
||
| 162 | } |
||
| 163 | |||
| 164 | if (true === $this->commandData->getOption('localized')) { |
||
| 165 | $this->saveLocaleFile(); |
||
| 166 | } |
||
| 167 | |||
| 168 | if (false === $this->isSkip('dump-autoload')) { |
||
| 169 | $this->info('Generating autoload files'); |
||
| 170 | $this->composer->dumpOptimized(); |
||
| 171 | } |
||
| 172 | } |
||
| 173 | |||
| 174 | /** |
||
| 175 | * Save the Schema File. |
||
| 176 | * |
||
| 177 | * @return void |
||
| 178 | */ |
||
| 179 | private function saveSchemaFile() |
||
| 215 | } |
||
| 216 | |||
| 217 | /** |
||
| 218 | * Save the Locale File. |
||
| 219 | * |
||
| 220 | * @return void |
||
| 221 | */ |
||
| 222 | private function saveLocaleFile() |
||
| 245 | } |
||
| 246 | } |
||
| 247 |