| Conditions | 8 | 
| Paths | 14 | 
| Total Lines | 71 | 
| Code Lines | 53 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php | ||
| 39 | protected function execute(InputInterface $input, OutputInterface $output) | ||
| 40 |     { | ||
| 41 | $output->writeln(['<comment>Welcome to the schema generator</comment>']); | ||
| 42 | |||
| 43 |         $helper    = $this->getHelper('question'); | ||
| 44 |         $question  = new Question('<info>Please enter table name: </info>'); | ||
| 45 | $tableName = $helper->ask($input, $output, $question); | ||
| 46 | |||
| 47 | $table = Capsule::schema()->getColumnListing($tableName); | ||
| 48 |         if (count($table) === 0) { | ||
| 49 |             $output->writeln([sprintf('<comment>Not found table %s</comment>', $tableName)]); | ||
| 50 | } | ||
| 51 | |||
| 52 | $columns = []; | ||
| 53 |         foreach ($table as $columnName) { | ||
| 54 | $columnType = Capsule::schema()->getColumnType($tableName, $columnName); | ||
| 55 | |||
| 56 |             switch ($columnType) { | ||
| 57 | case 'string': | ||
| 58 | case 'text': | ||
| 59 | $fake = '"String"'; | ||
| 60 | break; | ||
| 61 | case 'integer': | ||
| 62 | $fake = '1'; | ||
| 63 | break; | ||
| 64 | case 'decimal': | ||
| 65 | $fake = '1.0'; | ||
| 66 | break; | ||
| 67 | case 'datetime': | ||
| 68 | $fake = '"2016-10-17T07:38:21+0000"'; | ||
| 69 | break; | ||
| 70 | default: | ||
| 71 | $fake = ''; | ||
| 72 | } | ||
| 73 | |||
| 74 | $columns[] = [ | ||
| 75 | 'name' => $columnName, | ||
| 76 | 'type' => $columnType, | ||
| 77 | 'fake' => $fake, | ||
| 78 | ]; | ||
| 79 | } | ||
| 80 | |||
| 81 | $modelName = substr($tableName, 0, -1); | ||
| 82 | $className = Helper::underscoreToCamelCase($modelName, true).'Schema'; | ||
| 83 | $baseName = $className.'.php'; | ||
| 84 | $path = $this->getPath($baseName, SCHEMAS_PATH); | ||
| 85 |         $resourceType = str_replace('_', '-', strtolower($modelName)); | ||
| 86 | |||
| 87 | $placeHolders = [ | ||
| 88 | '<class>', | ||
| 89 | '<resourceType>', | ||
| 90 | '<resourceTypeInCamelCase>', | ||
| 91 | '<attributes>', | ||
| 92 | '<params>', | ||
| 93 | '<attributesToClass>', | ||
| 94 | ]; | ||
| 95 | $replacements = [ | ||
| 96 | $className, | ||
| 97 |             str_replace('_', '-', strtolower($modelName)), | ||
| 98 | Helper::dashesToCamelCase($resourceType, true), | ||
| 99 | $this->generateAttributes($columns), | ||
| 100 | $this->generateParams($columns), | ||
| 101 | $this->generateAttributesToClass($columns), | ||
| 102 | ]; | ||
| 103 | |||
| 104 | $this->generateCode($placeHolders, $replacements, 'SchemaTemplate.tpl', $path); | ||
| 105 | |||
| 106 |         $output->writeln(sprintf('Generated new schema class to "<info>%s</info>"', realpath($path))); | ||
| 107 | |||
| 108 | return; | ||
| 109 | } | ||
| 110 | |||
| 173 |