| Conditions | 6 |
| Paths | 18 |
| Total Lines | 40 |
| Code Lines | 24 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 22 |
| CRAP Score | 6.0208 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 16 | 1 | public function run(Filesystem $filesystem, Framework $framework) |
|
| 17 | { |
||
| 18 | 1 | $time = time(); |
|
| 19 | 1 | $namespace = date('FY', $time); |
|
| 20 | 1 | $created_at = date('Y-m-d H:i:s', $time); |
|
| 21 | |||
| 22 | 1 | if (!is_array($this->name)) { |
|
| 23 | 1 | $this->name = explode(' ', $this->name); |
|
| 24 | } |
||
| 25 | |||
| 26 | 1 | if (!$this->name) { |
|
|
|
|||
| 27 | throw new Exception("No migration name defined!"); |
||
| 28 | } |
||
| 29 | |||
| 30 | 1 | $class = ''; |
|
| 31 | 1 | foreach ($this->name as $piece) { |
|
| 32 | 1 | $class .= ucfirst($piece); |
|
| 33 | } |
||
| 34 | |||
| 35 | 1 | $template = $framework->getPath('resources/templates/migration.php'); |
|
| 36 | |||
| 37 | 1 | ob_start(); |
|
| 38 | 1 | include($template); |
|
| 39 | 1 | $contents = ob_get_clean(); |
|
| 40 | |||
| 41 | 1 | $path = $filesystem->getPath('php/Migration'); |
|
| 42 | 1 | if (!is_dir($path)) { |
|
| 43 | mkdir($path); |
||
| 44 | } |
||
| 45 | |||
| 46 | 1 | $path = $filesystem->getPath('php/Migration/'.$namespace); |
|
| 47 | 1 | if (!is_dir($path)) { |
|
| 48 | 1 | mkdir($path); |
|
| 49 | } |
||
| 50 | |||
| 51 | 1 | $filename = 'php/Migration/'.$namespace.'/'.$class.'.php'; |
|
| 52 | 1 | file_put_contents($filename, $contents); |
|
| 53 | |||
| 54 | 1 | return compact('filename', 'namespace', 'class'); |
|
| 55 | } |
||
| 56 | } |
||
| 57 |
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.