| Conditions | 6 |
| Paths | 18 |
| Total Lines | 40 |
| Code Lines | 24 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 23 |
| CRAP Score | 6.0026 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 15 | 2 | public function run(Filesystem $filesystem, Framework $framework) |
|
| 16 | { |
||
| 17 | 2 | $time = time(); |
|
| 18 | 2 | $namespace = date('FY', $time); |
|
| 19 | 2 | $created_at = date('Y-m-d H:i:s', $time); |
|
| 20 | |||
| 21 | 2 | if (!is_array($this->name)) { |
|
| 22 | 2 | $this->name = explode(' ', $this->name); |
|
| 23 | } |
||
| 24 | |||
| 25 | 2 | if (!$this->name) { |
|
|
|
|||
| 26 | throw new Exception("No migration name defined!"); |
||
| 27 | } |
||
| 28 | |||
| 29 | 2 | $class = ''; |
|
| 30 | 2 | foreach ($this->name as $piece) { |
|
| 31 | 2 | $class .= ucfirst($piece); |
|
| 32 | } |
||
| 33 | |||
| 34 | 2 | $template = $framework->getPath('resources/templates/migration.php'); |
|
| 35 | |||
| 36 | 2 | ob_start(); |
|
| 37 | 2 | include($template); |
|
| 38 | 2 | $contents = ob_get_clean(); |
|
| 39 | |||
| 40 | 2 | $path = $filesystem->getPath('php/Migration'); |
|
| 41 | 2 | if (!is_dir($path)) { |
|
| 42 | 1 | mkdir($path); |
|
| 43 | } |
||
| 44 | |||
| 45 | 2 | $path = $filesystem->getPath('php/Migration/'.$namespace); |
|
| 46 | 2 | if (!is_dir($path)) { |
|
| 47 | 2 | mkdir($path); |
|
| 48 | } |
||
| 49 | |||
| 50 | 2 | $filename = 'php/Migration/'.$namespace.'/'.$class.'.php'; |
|
| 51 | 2 | file_put_contents($filename, $contents); |
|
| 52 | |||
| 53 | 2 | return compact('filename', 'namespace', 'class'); |
|
| 54 | } |
||
| 55 | } |
||
| 56 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.