Skip to content

Commit 2196278

Browse files
committed
refactor: use InputOutput::error()
1 parent 0ea6604 commit 2196278

1 file changed

Lines changed: 18 additions & 10 deletions

File tree

src/Commands/Setup.php

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ protected function writeFile(string $file, string $content): void
175175
! $overwrite
176176
&& $this->prompt(" File '{$cleanPath}' already exists in destination. Overwrite?", ['n', 'y']) === 'n'
177177
) {
178-
CLI::error(" Skipped {$cleanPath}. If you wish to overwrite, please use the '-f' option or reply 'y' to the prompt.");
178+
$this->error(" Skipped {$cleanPath}. If you wish to overwrite, please use the '-f' option or reply 'y' to the prompt.");
179179

180180
return;
181181
}
@@ -184,7 +184,7 @@ protected function writeFile(string $file, string $content): void
184184
if (write_file($path, $content)) {
185185
$this->write(CLI::color(' Created: ', 'green') . $cleanPath);
186186
} else {
187-
CLI::error(" Error creating {$cleanPath}.");
187+
$this->error(" Error creating {$cleanPath}.");
188188
}
189189
}
190190

@@ -202,20 +202,20 @@ protected function add(string $file, string $code, string $pattern, string $repl
202202
$output = $this->replacer->add($content, $code, $pattern, $replace);
203203

204204
if ($output === true) {
205-
CLI::error(" Skipped {$cleanPath}. It has already been updated.");
205+
$this->error(" Skipped {$cleanPath}. It has already been updated.");
206206

207207
return;
208208
}
209209
if ($output === false) {
210-
CLI::error(" Error checking {$cleanPath}.");
210+
$this->error(" Error checking {$cleanPath}.");
211211

212212
return;
213213
}
214214

215215
if (write_file($path, $output)) {
216216
$this->write(CLI::color(' Updated: ', 'green') . $cleanPath);
217217
} else {
218-
CLI::error(" Error updating {$cleanPath}.");
218+
$this->error(" Error updating {$cleanPath}.");
219219
}
220220
}
221221

@@ -244,7 +244,7 @@ private function replace(string $file, array $replaces): bool
244244
return true;
245245
}
246246

247-
CLI::error(" Error updating {$cleanPath}.");
247+
$this->error(" Error updating {$cleanPath}.");
248248

249249
return false;
250250
}
@@ -294,7 +294,7 @@ private function setSecurityCSRF(): void
294294
$cleanPath = clean_path($path);
295295

296296
if (! is_file($path)) {
297-
CLI::error(" Not found file '{$cleanPath}'.");
297+
$this->error(" Not found file '{$cleanPath}'.");
298298

299299
return;
300300
}
@@ -312,7 +312,7 @@ private function setSecurityCSRF(): void
312312
if (write_file($path, $output)) {
313313
$this->write(CLI::color(' Updated: ', 'green') . "We have updated file '{$cleanPath}' for security reasons.");
314314
} else {
315-
CLI::error(" Error updating file '{$cleanPath}'.");
315+
$this->error(" Error updating file '{$cleanPath}'.");
316316
}
317317
}
318318

@@ -324,7 +324,7 @@ private function setupEmail(): void
324324
$cleanPath = clean_path($path);
325325

326326
if (! is_file($path)) {
327-
CLI::error(" Not found file '{$cleanPath}'.");
327+
$this->error(" Not found file '{$cleanPath}'.");
328328

329329
return;
330330
}
@@ -370,7 +370,7 @@ private function setupEmail(): void
370370
if (write_file($path, $output)) {
371371
$this->write(CLI::color(' Updated: ', 'green') . $cleanPath);
372372
} else {
373-
CLI::error(" Error updating file '{$cleanPath}'.");
373+
$this->error(" Error updating file '{$cleanPath}'.");
374374
}
375375
}
376376

@@ -416,6 +416,14 @@ private function write(
416416
self::$io->write($text, $foreground, $background);
417417
}
418418

419+
private function error(
420+
string $text,
421+
string $foreground = 'light_red',
422+
?string $background = null
423+
): void {
424+
self::$io->error($text, $foreground, $background);
425+
}
426+
419427
private function ensureInputOutput(): void
420428
{
421429
if (self::$io === null) {

0 commit comments

Comments
 (0)