| Conditions | 9 |
| Paths | 69 |
| Total Lines | 98 |
| Code Lines | 75 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 56 | public function execute() |
||
| 57 | { |
||
| 58 | $this->__callOptions(); |
||
| 59 | |||
| 60 | if (empty($this->optionFilename)) { |
||
| 61 | output()->write( |
||
| 62 | (new Format()) |
||
| 63 | ->setContextualClass(Format::DANGER) |
||
| 64 | ->setString(language()->getLine('CLI_MAKE_MODEL_E_FILENAME')) |
||
| 65 | ->setNewLinesAfter(1) |
||
| 66 | ); |
||
| 67 | |||
| 68 | exit(EXIT_ERROR); |
||
| 69 | } |
||
| 70 | |||
| 71 | if (strpos($this->optionPath, 'Models') === false) { |
||
| 72 | $filePath = $this->optionPath . 'Models' . DIRECTORY_SEPARATOR . $this->optionFilename; |
||
| 73 | } else { |
||
| 74 | $filePath = $this->optionPath . $this->optionFilename; |
||
| 75 | } |
||
| 76 | |||
| 77 | if ( ! is_dir(dirname($filePath))) { |
||
| 78 | mkdir(dirname($filePath), 0777, true); |
||
| 79 | } |
||
| 80 | |||
| 81 | if (is_file($filePath)) { |
||
| 82 | output()->write( |
||
| 83 | (new Format()) |
||
| 84 | ->setContextualClass(Format::DANGER) |
||
| 85 | ->setString(language()->getLine('CLI_MAKE_MODEL_E_EXISTS', [$filePath])) |
||
| 86 | ->setNewLinesAfter(1) |
||
| 87 | ); |
||
| 88 | |||
| 89 | exit(EXIT_ERROR); |
||
| 90 | } |
||
| 91 | |||
| 92 | $className = prepare_class_name(pathinfo($filePath, PATHINFO_FILENAME)); |
||
| 93 | @list($namespaceDirectory, $subNamespace) = explode('Models', dirname($filePath)); |
||
| 94 | |||
| 95 | $classNamespace = loader()->getDirNamespace( |
||
| 96 | $namespaceDirectory |
||
| 97 | ) . 'Models' . (empty($subNamespace) |
||
| 98 | ? null |
||
| 99 | : str_replace( |
||
| 100 | '/', |
||
| 101 | '\\', |
||
| 102 | $subNamespace |
||
| 103 | )) . '\\'; |
||
| 104 | |||
| 105 | $isUseORM = empty($this->isUseORM) ? false : true; |
||
| 106 | |||
| 107 | $vars[ 'CREATE_DATETIME' ] = date('d/m/Y H:m'); |
||
| 108 | $vars[ 'NAMESPACE' ] = trim($classNamespace, '\\'); |
||
| 109 | $vars[ 'PACKAGE' ] = '\\' . trim($classNamespace, '\\'); |
||
| 110 | $vars[ 'CLASS' ] = $className; |
||
| 111 | $vars[ 'FILEPATH' ] = $filePath; |
||
| 112 | $vars[ 'EXTEND' ] = $isUseORM |
||
| 113 | ? 'Orm' |
||
| 114 | : 'Reactor'; |
||
| 115 | |||
| 116 | $phpTemplate = <<<PHPTEMPLATE |
||
| 117 | <?php |
||
| 118 | /** |
||
| 119 | * Created by O2System Reactor File Generator. |
||
| 120 | * DateTime: CREATE_DATETIME |
||
| 121 | */ |
||
| 122 | |||
| 123 | // ------------------------------------------------------------------------ |
||
| 124 | |||
| 125 | namespace NAMESPACE; |
||
| 126 | |||
| 127 | // ------------------------------------------------------------------------ |
||
| 128 | |||
| 129 | use O2System\Reactor\Models\Sql\Model; |
||
| 130 | |||
| 131 | /** |
||
| 132 | * Class CLASS |
||
| 133 | * |
||
| 134 | * @package PACKAGE |
||
| 135 | */ |
||
| 136 | class CLASS extends Model |
||
| 137 | { |
||
| 138 | public \$table = 'table_name'; |
||
| 139 | } |
||
| 140 | PHPTEMPLATE; |
||
| 141 | |||
| 142 | $fileContent = str_replace(array_keys($vars), array_values($vars), $phpTemplate); |
||
| 143 | file_put_contents($filePath, $fileContent); |
||
| 144 | |||
| 145 | if (is_file($filePath)) { |
||
| 146 | output()->write( |
||
| 147 | (new Format()) |
||
| 148 | ->setContextualClass(Format::SUCCESS) |
||
| 149 | ->setString(language()->getLine('CLI_MAKE_MODEL_S_MAKE', [$filePath])) |
||
| 150 | ->setNewLinesAfter(1) |
||
| 151 | ); |
||
| 152 | |||
| 153 | exit(EXIT_SUCCESS); |
||
| 154 | } |
||
| 157 | } |