|
8 | 8 |
|
9 | 9 | class AutocompleteCommand extends Command
|
10 | 10 | {
|
11 |
| - protected $signature = 'autocomplete {code} {--debug} {--from-file=}'; |
| 11 | + use ResolvesCode; |
| 12 | + |
| 13 | + protected $signature = 'autocomplete {code} {--from-file} {--debug} {--local-file=}'; |
12 | 14 |
|
13 | 15 | protected $description = 'Parse the given PHP code and return the autocomplete results';
|
14 | 16 |
|
15 | 17 | public function handle(): void
|
16 | 18 | {
|
17 |
| - $code = $this->argument('code'); |
18 |
| - |
19 |
| - if ($this->option('from-file')) { |
20 |
| - $code = file_get_contents(__DIR__ . '/../../tests/snippets/parse/' . $this->option('from-file') . '.php'); |
21 |
| - } |
| 19 | + $code = $this->resolveCode('autocomplete'); |
22 | 20 |
|
23 | 21 | $walker = new Walker($code, (bool) $this->option('debug'));
|
24 | 22 | $result = $walker->walk();
|
25 | 23 |
|
26 | 24 | $autocompleting = $result->findAutocompleting();
|
27 | 25 |
|
28 | 26 | if (app()->isLocal()) {
|
29 |
| - $dir = 'local-results/autocomplete'; |
30 |
| - File::ensureDirectoryExists(storage_path($dir)); |
31 |
| - $now = now()->format('Y-m-d-H-i-s'); |
32 |
| - |
33 |
| - if (!$this->option('from-file')) { |
34 |
| - File::put(storage_path("{$dir}/{$now}-01-code.php"), $code); |
35 |
| - } |
36 |
| - |
37 |
| - File::put(storage_path("{$dir}/{$now}-02-autocomplete.json"), json_encode($autocompleting?->flip() ?? [], JSON_PRETTY_PRINT)); |
38 |
| - File::put(storage_path("{$dir}/{$now}-03-full.json"), $result->toJson(JSON_PRETTY_PRINT)); |
| 27 | + $this->log($autocompleting, $result, $code); |
39 | 28 | }
|
40 | 29 |
|
41 | 30 | echo json_encode($autocompleting?->flip() ?? [], $this->option('debug') ? JSON_PRETTY_PRINT : 0);
|
| 31 | + } |
| 32 | + |
| 33 | + protected function log($autocompleting, $result, $code) |
| 34 | + { |
| 35 | + $dir = 'local-results/autocomplete'; |
| 36 | + File::ensureDirectoryExists(storage_path($dir)); |
| 37 | + $now = now()->format('Y-m-d-H-i-s'); |
42 | 38 |
|
43 |
| - // dd($autocompleting->flip(), 'Autocompleting'); |
44 |
| - // // $toAutocomplete = $this->findFirstAutocompleting($result->toArray()['children']); |
| 39 | + if (!$this->option('local-file')) { |
| 40 | + File::put(storage_path("{$dir}/{$now}-01-code.php"), $code); |
| 41 | + } |
45 | 42 |
|
46 |
| - // echo $result->toJson($this->option('debug') ? JSON_PRETTY_PRINT : 0); |
| 43 | + File::put(storage_path("{$dir}/{$now}-02-autocomplete.json"), json_encode($autocompleting?->flip() ?? [], JSON_PRETTY_PRINT)); |
| 44 | + File::put(storage_path("{$dir}/{$now}-03-full.json"), $result->toJson(JSON_PRETTY_PRINT)); |
47 | 45 | }
|
48 | 46 | }
|
0 commit comments