Skip to content

Commit 6a97a03

Browse files
committed
style: break long lines
1 parent c90053b commit 6a97a03

File tree

2 files changed

+111
-20
lines changed

2 files changed

+111
-20
lines changed

system/CLI/GeneratorTrait.php

Lines changed: 106 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,13 @@ private function generateFile(string $target, string $content): void
143143
CLI::write(lang('CLI.generator.usingCINamespace'), 'yellow');
144144
CLI::newLine();
145145

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+
) {
147153
CLI::newLine();
148154
CLI::write(lang('CLI.generator.cancelOperation'), 'yellow');
149155
CLI::newLine();
@@ -160,7 +166,11 @@ private function generateFile(string $target, string $content): void
160166
// Overwriting files unknowingly is a serious annoyance, So we'll check if
161167
// we are duplicating things, If 'force' option is not supplied, we bail.
162168
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+
);
164174
CLI::newLine();
165175

166176
return;
@@ -179,21 +189,31 @@ private function generateFile(string $target, string $content): void
179189
// contents from the template, and then we'll do the necessary replacements.
180190
if (! write_file($target, $content)) {
181191
// @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+
);
183197
CLI::newLine();
184198

185199
return;
186200
// @codeCoverageIgnoreEnd
187201
}
188202

189203
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+
);
191208
CLI::newLine();
192209

193210
return;
194211
}
195212

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+
);
197217
CLI::newLine();
198218
}
199219

@@ -244,15 +264,34 @@ protected function qualifyClassName(): string
244264
$class = $matches[1] . ucfirst($matches[2]);
245265
}
246266

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+
) {
248271
$class .= ucfirst($component);
249272
}
250273

251274
// 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+
);
253285

254286
// 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+
) . '\\';
256295

257296
if (strncmp($class, $namespace, strlen($namespace)) === 0) {
258297
return $class; // @codeCoverageIgnore
@@ -268,21 +307,39 @@ protected function qualifyClassName(): string
268307
protected function renderTemplate(array $data = []): string
269308
{
270309
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+
);
272315
} catch (Throwable $e) {
273316
log_message('error', (string) $e);
274317

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+
);
276323
}
277324
}
278325

279326
/**
280327
* Performs pseudo-variables contained within view file.
281328
*/
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 {
284335
// 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+
);
286343
$search[] = '<@php';
287344
$search[] = '{namespace}';
288345
$search[] = '{class}';
@@ -302,7 +359,14 @@ protected function buildContent(string $class): string
302359
{
303360
$template = $this->prepare($class);
304361

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+
) {
306370
$imports = explode("\n", trim($match['imports']));
307371
sort($imports);
308372

@@ -317,22 +381,45 @@ protected function buildContent(string $class): string
317381
*/
318382
protected function buildPath(string $class): string
319383
{
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+
);
321392

322393
// Check if the namespace is actually defined and we are not just typing gibberish.
323394
$base = Services::autoloader()->getNamespace($namespace);
324395

325396
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+
);
327402
CLI::newLine();
328403

329404
return '';
330405
}
331406

332407
$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);
336423
}
337424

338425
/**

system/Commands/Generators/CellGenerator.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,11 @@ public function run(array $params)
8888

8989
$className = $this->qualifyClassName();
9090
$viewName = decamelize(class_basename($className));
91-
$viewName = preg_replace('/([a-z][a-z0-9_\/\\\\]+)(_cell)$/i', '$1', $viewName) ?? $viewName;
91+
$viewName = preg_replace(
92+
'/([a-z][a-z0-9_\/\\\\]+)(_cell)$/i',
93+
'$1',
94+
$viewName
95+
) ?? $viewName;
9296
$namespace = substr($className, 0, strrpos($className, '\\') + 1);
9397

9498
$this->generateView($namespace . $viewName, $params);

0 commit comments

Comments
 (0)