@@ -143,7 +143,13 @@ private function generateFile(string $target, string $content): void
143
143
CLI ::write (lang ('CLI.generator.usingCINamespace ' ), 'yellow ' );
144
144
CLI ::newLine ();
145
145
146
- if (CLI ::prompt ('Are you sure you want to continue? ' , ['y ' , 'n ' ], 'required ' ) === 'n ' ) {
146
+ if (
147
+ CLI ::prompt (
148
+ 'Are you sure you want to continue? ' ,
149
+ ['y ' , 'n ' ],
150
+ 'required '
151
+ ) === 'n '
152
+ ) {
147
153
CLI ::newLine ();
148
154
CLI ::write (lang ('CLI.generator.cancelOperation ' ), 'yellow ' );
149
155
CLI ::newLine ();
@@ -160,7 +166,11 @@ private function generateFile(string $target, string $content): void
160
166
// Overwriting files unknowingly is a serious annoyance, So we'll check if
161
167
// we are duplicating things, If 'force' option is not supplied, we bail.
162
168
if (! $ this ->getOption ('force ' ) && $ isFile ) {
163
- CLI ::error (lang ('CLI.generator.fileExist ' , [clean_path ($ target )]), 'light_gray ' , 'red ' );
169
+ CLI ::error (
170
+ lang ('CLI.generator.fileExist ' , [clean_path ($ target )]),
171
+ 'light_gray ' ,
172
+ 'red '
173
+ );
164
174
CLI ::newLine ();
165
175
166
176
return ;
@@ -179,21 +189,31 @@ private function generateFile(string $target, string $content): void
179
189
// contents from the template, and then we'll do the necessary replacements.
180
190
if (! write_file ($ target , $ content )) {
181
191
// @codeCoverageIgnoreStart
182
- CLI ::error (lang ('CLI.generator.fileError ' , [clean_path ($ target )]), 'light_gray ' , 'red ' );
192
+ CLI ::error (
193
+ lang ('CLI.generator.fileError ' , [clean_path ($ target )]),
194
+ 'light_gray ' ,
195
+ 'red '
196
+ );
183
197
CLI ::newLine ();
184
198
185
199
return ;
186
200
// @codeCoverageIgnoreEnd
187
201
}
188
202
189
203
if ($ this ->getOption ('force ' ) && $ isFile ) {
190
- CLI ::write (lang ('CLI.generator.fileOverwrite ' , [clean_path ($ target )]), 'yellow ' );
204
+ CLI ::write (
205
+ lang ('CLI.generator.fileOverwrite ' , [clean_path ($ target )]),
206
+ 'yellow '
207
+ );
191
208
CLI ::newLine ();
192
209
193
210
return ;
194
211
}
195
212
196
- CLI ::write (lang ('CLI.generator.fileCreate ' , [clean_path ($ target )]), 'green ' );
213
+ CLI ::write (
214
+ lang ('CLI.generator.fileCreate ' , [clean_path ($ target )]),
215
+ 'green '
216
+ );
197
217
CLI ::newLine ();
198
218
}
199
219
@@ -244,15 +264,34 @@ protected function qualifyClassName(): string
244
264
$ class = $ matches [1 ] . ucfirst ($ matches [2 ]);
245
265
}
246
266
247
- if ($ this ->enabledSuffixing && $ this ->getOption ('suffix ' ) && preg_match ($ pattern , $ class ) !== 1 ) {
267
+ if (
268
+ $ this ->enabledSuffixing && $ this ->getOption ('suffix ' )
269
+ && preg_match ($ pattern , $ class ) !== 1
270
+ ) {
248
271
$ class .= ucfirst ($ component );
249
272
}
250
273
251
274
// Trims input, normalize separators, and ensure that all paths are in Pascalcase.
252
- $ class = ltrim (implode ('\\' , array_map ('pascalize ' , explode ('\\' , str_replace ('/ ' , '\\' , trim ($ class ))))), '\\/ ' );
275
+ $ class = ltrim (
276
+ implode (
277
+ '\\' ,
278
+ array_map (
279
+ 'pascalize ' ,
280
+ explode ('\\' , str_replace ('/ ' , '\\' , trim ($ class )))
281
+ )
282
+ ),
283
+ '\\/ '
284
+ );
253
285
254
286
// Gets the namespace from input. Don't forget the ending backslash!
255
- $ namespace = trim (str_replace ('/ ' , '\\' , $ this ->getOption ('namespace ' ) ?? APP_NAMESPACE ), '\\' ) . '\\' ;
287
+ $ namespace = trim (
288
+ str_replace (
289
+ '/ ' ,
290
+ '\\' ,
291
+ $ this ->getOption ('namespace ' ) ?? APP_NAMESPACE
292
+ ),
293
+ '\\'
294
+ ) . '\\' ;
256
295
257
296
if (strncmp ($ class , $ namespace , strlen ($ namespace )) === 0 ) {
258
297
return $ class ; // @codeCoverageIgnore
@@ -268,21 +307,39 @@ protected function qualifyClassName(): string
268
307
protected function renderTemplate (array $ data = []): string
269
308
{
270
309
try {
271
- return view (config (Generators::class)->views [$ this ->name ], $ data , ['debug ' => false ]);
310
+ return view (
311
+ config (Generators::class)->views [$ this ->name ],
312
+ $ data ,
313
+ ['debug ' => false ]
314
+ );
272
315
} catch (Throwable $ e ) {
273
316
log_message ('error ' , (string ) $ e );
274
317
275
- return view ("CodeIgniter \\Commands \\Generators \\Views \\{$ this ->template }" , $ data , ['debug ' => false ]);
318
+ return view (
319
+ "CodeIgniter \\Commands \\Generators \\Views \\{$ this ->template }" ,
320
+ $ data ,
321
+ ['debug ' => false ]
322
+ );
276
323
}
277
324
}
278
325
279
326
/**
280
327
* Performs pseudo-variables contained within view file.
281
328
*/
282
- protected function parseTemplate (string $ class , array $ search = [], array $ replace = [], array $ data = []): string
283
- {
329
+ protected function parseTemplate (
330
+ string $ class ,
331
+ array $ search = [],
332
+ array $ replace = [],
333
+ array $ data = []
334
+ ): string {
284
335
// Retrieves the namespace part from the fully qualified class name.
285
- $ namespace = trim (implode ('\\' , array_slice (explode ('\\' , $ class ), 0 , -1 )), '\\' );
336
+ $ namespace = trim (
337
+ implode (
338
+ '\\' ,
339
+ array_slice (explode ('\\' , $ class ), 0 , -1 )
340
+ ),
341
+ '\\'
342
+ );
286
343
$ search [] = '<@php ' ;
287
344
$ search [] = '{namespace} ' ;
288
345
$ search [] = '{class} ' ;
@@ -302,7 +359,14 @@ protected function buildContent(string $class): string
302
359
{
303
360
$ template = $ this ->prepare ($ class );
304
361
305
- if ($ this ->sortImports && preg_match ('/(?P<imports>(?:^use [^;]+;$\n?)+)/m ' , $ template , $ match )) {
362
+ if (
363
+ $ this ->sortImports
364
+ && preg_match (
365
+ '/(?P<imports>(?:^use [^;]+;$\n?)+)/m ' ,
366
+ $ template ,
367
+ $ match
368
+ )
369
+ ) {
306
370
$ imports = explode ("\n" , trim ($ match ['imports ' ]));
307
371
sort ($ imports );
308
372
@@ -317,22 +381,45 @@ protected function buildContent(string $class): string
317
381
*/
318
382
protected function buildPath (string $ class ): string
319
383
{
320
- $ namespace = trim (str_replace ('/ ' , '\\' , $ this ->getOption ('namespace ' ) ?? APP_NAMESPACE ), '\\' );
384
+ $ namespace = trim (
385
+ str_replace (
386
+ '/ ' ,
387
+ '\\' ,
388
+ $ this ->getOption ('namespace ' ) ?? APP_NAMESPACE
389
+ ),
390
+ '\\'
391
+ );
321
392
322
393
// Check if the namespace is actually defined and we are not just typing gibberish.
323
394
$ base = Services::autoloader ()->getNamespace ($ namespace );
324
395
325
396
if (! $ base = reset ($ base )) {
326
- CLI ::error (lang ('CLI.namespaceNotDefined ' , [$ namespace ]), 'light_gray ' , 'red ' );
397
+ CLI ::error (
398
+ lang ('CLI.namespaceNotDefined ' , [$ namespace ]),
399
+ 'light_gray ' ,
400
+ 'red '
401
+ );
327
402
CLI ::newLine ();
328
403
329
404
return '' ;
330
405
}
331
406
332
407
$ base = realpath ($ base ) ?: $ base ;
333
- $ file = $ base . DIRECTORY_SEPARATOR . str_replace ('\\' , DIRECTORY_SEPARATOR , trim (str_replace ($ namespace . '\\' , '' , $ class ), '\\' )) . '.php ' ;
334
-
335
- return implode (DIRECTORY_SEPARATOR , array_slice (explode (DIRECTORY_SEPARATOR , $ file ), 0 , -1 )) . DIRECTORY_SEPARATOR . $ this ->basename ($ file );
408
+ $ file = $ base . DIRECTORY_SEPARATOR
409
+ . str_replace (
410
+ '\\' ,
411
+ DIRECTORY_SEPARATOR ,
412
+ trim (str_replace ($ namespace . '\\' , '' , $ class ), '\\' )
413
+ ) . '.php ' ;
414
+
415
+ return implode (
416
+ DIRECTORY_SEPARATOR ,
417
+ array_slice (
418
+ explode (DIRECTORY_SEPARATOR , $ file ),
419
+ 0 ,
420
+ -1
421
+ )
422
+ ) . DIRECTORY_SEPARATOR . $ this ->basename ($ file );
336
423
}
337
424
338
425
/**
0 commit comments