Skip to content

Commit 6e595b2

Browse files
committed
refactor: extract methods
1 parent de3f3db commit 6e595b2

File tree

1 file changed

+41
-10
lines changed

1 file changed

+41
-10
lines changed

system/Commands/Utilities/FilterCheck.php

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,7 @@ class FilterCheck extends BaseCommand
7373
*/
7474
public function run(array $params)
7575
{
76-
$tbody = [];
77-
if (! isset($params[0], $params[1])) {
78-
CLI::error('You must specify a HTTP verb and a route.');
79-
CLI::write(' Usage: ' . $this->usage);
80-
CLI::write('Example: filter:check GET /');
81-
CLI::write(' filter:check PUT products/1');
82-
76+
if (! $this->checkParams($params)) {
8377
return EXIT_ERROR;
8478
}
8579

@@ -107,6 +101,40 @@ public function run(array $params)
107101
return EXIT_ERROR;
108102
}
109103

104+
$this->showTable($filterCollector, $filters, $method, $route);
105+
$this->showFilterClasses($filterCollector, $method, $route);
106+
107+
return EXIT_SUCCESS;
108+
}
109+
110+
/**
111+
* @param array<int|string, string|null> $params
112+
*/
113+
private function checkParams(array $params): bool
114+
{
115+
if (! isset($params[0], $params[1])) {
116+
CLI::error('You must specify a HTTP verb and a route.');
117+
CLI::write(' Usage: ' . $this->usage);
118+
CLI::write('Example: filter:check GET /');
119+
CLI::write(' filter:check PUT products/1');
120+
121+
return false;
122+
}
123+
124+
return true;
125+
}
126+
127+
/**
128+
* @param array{before: list<string>, after: list<string>} $filters
129+
*/
130+
private function showTable(
131+
FilterCollector $filterCollector,
132+
array $filters,
133+
string $method,
134+
string $route
135+
): void {
136+
$tbody = [];
137+
110138
$filters = $this->addRequiredFilters($filterCollector, $filters);
111139

112140
$tbody[] = [
@@ -124,8 +152,13 @@ public function run(array $params)
124152
];
125153

126154
CLI::table($tbody, $thead);
155+
}
127156

128-
// Show filter classes
157+
private function showFilterClasses(
158+
FilterCollector $filterCollector,
159+
string $method,
160+
string $route
161+
): void {
129162
$requiredFilterClasses = $filterCollector->getRequiredFilterClasses();
130163
$filterClasses = $filterCollector->getClasses($method, $route);
131164

@@ -146,8 +179,6 @@ public function run(array $params)
146179
CLI::write(ucfirst($position) . ' Filter Classes:', 'cyan');
147180
CLI::write(implode('', $classes));
148181
}
149-
150-
return EXIT_SUCCESS;
151182
}
152183

153184
private function addRequiredFilters(FilterCollector $filterCollector, array $filters): array

0 commit comments

Comments
 (0)