2727 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2828 * THE SOFTWARE.
2929 *
30- * @package CodeIgniter
31- * @author CodeIgniter Dev Team
32- * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/)
33- * @license https://opensource.org/licenses/MIT MIT License
34- * @link https://codeigniter.com
35- * @since Version 3.0.0
30+ * @package CodeIgniter
31+ * @author CodeIgniter Dev Team
32+ * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/)
33+ * @license https://opensource.org/licenses/MIT MIT License
34+ * @link https://codeigniter.com
35+ * @since Version 3.0.0
3636 * @filesource
3737 */
38+
3839use CodeIgniter \CLI \BaseCommand ;
3940use CodeIgniter \CLI \CLI ;
4041use Config \Autoload ;
@@ -83,7 +84,7 @@ class CreateMigration extends BaseCommand
8384 * @var array
8485 */
8586 protected $ arguments = [
86- 'migration_name ' => 'The migration file name '
87+ 'migration_name ' => 'The migration file name ' ,
8788 ];
8889
8990 /**
@@ -92,7 +93,7 @@ class CreateMigration extends BaseCommand
9293 * @var array
9394 */
9495 protected $ options = [
95- '-n ' => 'Set migration namespace '
96+ '-n ' => 'Set migration namespace ' ,
9697 ];
9798
9899 /**
@@ -104,7 +105,6 @@ class CreateMigration extends BaseCommand
104105 */
105106 public function run (array $ params = [])
106107 {
107-
108108 $ name = array_shift ($ params );
109109
110110 if (empty ($ name ))
@@ -117,19 +117,18 @@ public function run(array $params = [])
117117 CLI ::error (lang ('Migrations.badCreateName ' ));
118118 return ;
119119 }
120- $ ns = CLI ::getOption ('n ' );
120+ $ ns = CLI ::getOption ('n ' );
121121 $ homepath = APPPATH ;
122122
123- if ( ! empty ($ ns ))
123+ if (! empty ($ ns ))
124124 {
125125 // Get all namespaces form PSR4 paths.
126- $ config = new Autoload ();
126+ $ config = new Autoload ();
127127 $ namespaces = $ config ->psr4 ;
128128
129129 foreach ($ namespaces as $ namespace => $ path )
130130 {
131-
132- if ($ namespace == $ ns )
131+ if ($ namespace === $ ns )
133132 {
134133 $ homepath = realpath ($ path );
135134 break ;
@@ -138,38 +137,39 @@ public function run(array $params = [])
138137 }
139138 else
140139 {
141- $ ns = " App " ;
140+ $ ns = ' App ' ;
142141 }
143142
144143 // Migrations Config
145- $ config = new Migrations ();
146-
147- if ($ config ->type != 'timestamp ' && $ config ->type != 'sequential ' )
148- {
149- CLI ::error (lang ('Migrations.invalidType ' , [$ config ->type ]));
150- return ;
151- }
152-
153- // migration Type
154- if ($ config ->type === 'timestamp ' )
155- {
156- $ name = date ('YmdHis_ ' ) . $ name ;
157- } else if ($ config ->type === 'sequential ' )
158- {
159- // default with 001
160- $ sequence = $ params [0 ] ?? '001 ' ;
161- // number must be three digits
162- if (! is_numeric ($ sequence ) || strlen ($ sequence ) != 3 )
163- {
164- CLI ::error (lang ('Migrations.migNumberError ' ));
165- return ;
166- }
167-
168- $ name = $ sequence . '_ ' . $ name ;
169- }
170-
171- // full path
172- $ path = $ homepath . '/Database/Migrations/ ' . $ name . '.php ' ;
144+ $ config = new Migrations ();
145+
146+ if ($ config ->type !== 'timestamp ' && $ config ->type !== 'sequential ' )
147+ {
148+ CLI ::error (lang ('Migrations.invalidType ' , [$ config ->type ]));
149+ return ;
150+ }
151+
152+ // migration Type
153+ if ($ config ->type === 'timestamp ' )
154+ {
155+ $ fileName = date ('YmdHis_ ' ) . $ name ;
156+ }
157+ else if ($ config ->type === 'sequential ' )
158+ {
159+ // default with 001
160+ $ sequence = $ params [0 ] ?? '001 ' ;
161+ // number must be three digits
162+ if (! is_numeric ($ sequence ) || strlen ($ sequence ) !== 3 )
163+ {
164+ CLI ::error (lang ('Migrations.migNumberError ' ));
165+ return ;
166+ }
167+
168+ $ fileName = $ sequence . '_ ' . $ name ;
169+ }
170+
171+ // full path
172+ $ path = $ homepath . '/Database/Migrations/ ' . $ fileName . '.php ' ;
173173
174174 $ template = <<<EOD
175175<?php namespace $ ns\Database\Migrations;
@@ -195,7 +195,7 @@ public function down()
195195 $ template = str_replace ('{name} ' , $ name , $ template );
196196
197197 helper ('filesystem ' );
198- if ( ! write_file ($ path , $ template ))
198+ if (! write_file ($ path , $ template ))
199199 {
200200 CLI ::error (lang ('Migrations.writeError ' ));
201201 return ;
0 commit comments