| Conditions | 7 |
| Paths | 21 |
| Total Lines | 80 |
| 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 |
||
| 65 | public function execute() |
||
| 66 | { |
||
| 67 | parent::execute(); |
||
| 68 | |||
| 69 | if (empty($this->optionName)) { |
||
| 70 | output()->write( |
||
|
|
|||
| 71 | (new Format()) |
||
| 72 | ->setContextualClass(Format::DANGER) |
||
| 73 | ->setString(language()->getLine('CLI_MAKE_MODULE_E_NAME')) |
||
| 74 | ->setNewLinesAfter(1) |
||
| 75 | ); |
||
| 76 | |||
| 77 | exit(EXIT_ERROR); |
||
| 78 | } |
||
| 79 | |||
| 80 | $moduleType = empty($this->moduleType) |
||
| 81 | ? 'Plugins' |
||
| 82 | : ucfirst(plural($this->moduleType)); |
||
| 83 | |||
| 84 | if (strpos($this->optionPath, $moduleType) === false) { |
||
| 85 | $modulePath = $this->optionPath . $moduleType . DIRECTORY_SEPARATOR . $this->optionName . DIRECTORY_SEPARATOR; |
||
| 86 | } else { |
||
| 87 | $modulePath = $this->optionPath . $this->optionName . DIRECTORY_SEPARATOR; |
||
| 88 | } |
||
| 89 | |||
| 90 | if ( ! is_dir($modulePath)) { |
||
| 91 | mkdir($modulePath, 0777, true); |
||
| 92 | } else { |
||
| 93 | output()->write( |
||
| 94 | (new Format()) |
||
| 95 | ->setContextualClass(Format::DANGER) |
||
| 96 | ->setString(language()->getLine('CLI_MAKE_PLUGIN_E_EXISTS', [$modulePath])) |
||
| 97 | ->setNewLinesAfter(1) |
||
| 98 | ); |
||
| 99 | |||
| 100 | exit(EXIT_ERROR); |
||
| 101 | } |
||
| 102 | |||
| 103 | $jsonProperties[ 'name' ] = readable( |
||
| 104 | pathinfo($modulePath, PATHINFO_FILENAME), |
||
| 105 | true |
||
| 106 | ); |
||
| 107 | |||
| 108 | if (empty($this->namespace)) { |
||
| 109 | @list($moduleDirectory, $moduleName) = explode($moduleType, dirname($modulePath)); |
||
| 110 | $namespace = loader()->getDirNamespace($moduleDirectory) . |
||
| 111 | $moduleType . '\\' . prepare_class_name( |
||
| 112 | $this->optionName |
||
| 113 | ) . '\\'; |
||
| 114 | } else { |
||
| 115 | $namespace = $this->namespace; |
||
| 116 | $jsonProperties[ 'namespace' ] = rtrim($namespace, '\\') . '\\'; |
||
| 117 | } |
||
| 118 | |||
| 119 | $jsonProperties[ 'created' ] = date('d M Y'); |
||
| 120 | |||
| 121 | loader()->addNamespace($namespace, $modulePath); |
||
| 122 | |||
| 123 | $fileContent = json_encode($jsonProperties, JSON_PRETTY_PRINT); |
||
| 124 | |||
| 125 | $filePath = $modulePath . strtolower(singular($moduleType)) . '.json'; |
||
| 126 | |||
| 127 | file_put_contents($filePath, $fileContent); |
||
| 128 | |||
| 129 | $this->optionPath = $modulePath; |
||
| 130 | $this->optionFilename = prepare_filename($this->optionName) . '.php'; |
||
| 131 | |||
| 132 | (new Controller()) |
||
| 133 | ->optionPath($this->optionPath) |
||
| 134 | ->optionFilename($this->optionFilename); |
||
| 135 | |||
| 136 | if (is_dir($modulePath)) { |
||
| 137 | output()->write( |
||
| 138 | (new Format()) |
||
| 139 | ->setContextualClass(Format::SUCCESS) |
||
| 140 | ->setString(language()->getLine('CLI_MAKE_PLUGIN_S_MAKE', [$modulePath])) |
||
| 141 | ->setNewLinesAfter(1) |
||
| 142 | ); |
||
| 143 | |||
| 144 | exit(EXIT_SUCCESS); |
||
| 145 | } |
||
| 147 | } |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.