|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Backpack\CRUD\app\Console\Commands\Upgrade; |
|
4
|
|
|
|
|
5
|
|
|
use Backpack\CRUD\app\Console\Commands\Upgrade\Concerns\ExtractsFirstInteger; |
|
6
|
|
|
|
|
7
|
|
|
abstract class Step |
|
8
|
|
|
{ |
|
9
|
|
|
use ExtractsFirstInteger; |
|
10
|
|
|
|
|
11
|
|
|
public function __construct(protected UpgradeContext $context) |
|
12
|
|
|
{ |
|
13
|
|
|
} |
|
14
|
|
|
|
|
15
|
|
|
abstract public function title(): string; |
|
16
|
|
|
|
|
17
|
|
|
public function description(): ?string |
|
18
|
|
|
{ |
|
19
|
|
|
return null; |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
abstract public function run(): StepResult; |
|
23
|
|
|
|
|
24
|
|
|
protected function context(): UpgradeContext |
|
25
|
|
|
{ |
|
26
|
|
|
return $this->context; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function canFix(StepResult $result): bool |
|
|
|
|
|
|
30
|
|
|
{ |
|
31
|
|
|
return false; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function fixMessage(StepResult $result): string |
|
|
|
|
|
|
35
|
|
|
{ |
|
36
|
|
|
return 'Apply automatic fix?'; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function fix(StepResult $result): StepResult |
|
|
|
|
|
|
40
|
|
|
{ |
|
41
|
|
|
return StepResult::skipped('No automatic fix available.'); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Build a preview of items with an optional formatter and overflow message. |
|
46
|
|
|
* |
|
47
|
|
|
* @param array<int, mixed> $items |
|
48
|
|
|
* @param callable|null $formatter |
|
49
|
|
|
* @return array<int, string> |
|
50
|
|
|
*/ |
|
51
|
|
|
protected function previewList( |
|
52
|
|
|
array $items, |
|
53
|
|
|
int $limit = 10, |
|
54
|
|
|
?callable $formatter = null, |
|
55
|
|
|
?string $overflowMessage = null |
|
56
|
|
|
): array { |
|
57
|
|
|
if (empty($items)) { |
|
58
|
|
|
return []; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
$formatter ??= static fn ($item): string => '- '.(string) $item; |
|
62
|
|
|
$preview = array_slice($items, 0, $limit); |
|
63
|
|
|
$details = array_map($formatter, $preview); |
|
64
|
|
|
|
|
65
|
|
|
$remaining = count($items) - count($preview); |
|
66
|
|
|
|
|
67
|
|
|
if ($remaining > 0) { |
|
68
|
|
|
$details[] = sprintf($overflowMessage ?? '... %d more item(s) omitted.', $remaining); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
return $details; |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.