Skip to content

Commit 4f584e6

Browse files
committed
wip
1 parent 7798718 commit 4f584e6

File tree

2 files changed

+31
-31
lines changed

2 files changed

+31
-31
lines changed

app/Commands/AutocompleteCommand.php

+14-14
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class AutocompleteCommand extends Command
1414

1515
public function handle(): void
1616
{
17-
$code = $this->argument('code');
17+
$code = base64_decode($this->argument('code'));
1818

1919
if ($this->option('from-file')) {
2020
$code = file_get_contents(__DIR__ . '/../../tests/snippets/parse/' . $this->option('from-file') . '.php');
@@ -26,23 +26,23 @@ public function handle(): void
2626
$autocompleting = $result->findAutocompleting();
2727

2828
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));
29+
$this->log($autocompleting, $result, $code);
3930
}
4031

4132
echo json_encode($autocompleting?->flip() ?? [], $this->option('debug') ? JSON_PRETTY_PRINT : 0);
33+
}
4234

43-
// dd($autocompleting->flip(), 'Autocompleting');
44-
// // $toAutocomplete = $this->findFirstAutocompleting($result->toArray()['children']);
35+
protected function log($autocompleting, $result, $code)
36+
{
37+
$dir = 'local-results/autocomplete';
38+
File::ensureDirectoryExists(storage_path($dir));
39+
$now = now()->format('Y-m-d-H-i-s');
40+
41+
if (!$this->option('from-file')) {
42+
File::put(storage_path("{$dir}/{$now}-01-code.php"), $code);
43+
}
4544

46-
// echo $result->toJson($this->option('debug') ? JSON_PRETTY_PRINT : 0);
45+
File::put(storage_path("{$dir}/{$now}-02-autocomplete.json"), json_encode($autocompleting?->flip() ?? [], JSON_PRETTY_PRINT));
46+
File::put(storage_path("{$dir}/{$now}-03-full.json"), $result->toJson(JSON_PRETTY_PRINT));
4747
}
4848
}

app/Commands/DetectCommand.php

+17-17
Original file line numberDiff line numberDiff line change
@@ -8,38 +8,38 @@
88

99
class DetectCommand extends Command
1010
{
11-
protected $signature = 'detect {path} {--debug} {--from-file=}';
11+
protected $signature = 'detect {code} {--debug} {--from-file=}';
1212

1313
protected $description = 'Detect things we care about in the current code';
1414

1515
public function handle(): void
1616
{
17+
$code = base64_decode($this->argument('code'));
18+
1719
if ($this->option('from-file')) {
1820
$code = file_get_contents(__DIR__ . '/../../tests/snippets/detect/' . $this->option('from-file') . '.php');
19-
} else {
20-
try {
21-
$code = file_get_contents($this->argument('path'));
22-
} catch (\Exception $e) {
23-
echo json_encode([]);
24-
return;
25-
}
2621
}
2722

2823
$walker = new DetectWalker($code, (bool) $this->option('debug'));
2924
$result = $walker->walk();
3025

3126
if (app()->isLocal()) {
32-
$dir = 'local-results/detect';
33-
File::ensureDirectoryExists(storage_path($dir));
34-
$now = now()->format('Y-m-d-H-i-s');
35-
36-
File::put(storage_path("{$dir}/result-{$now}.json"), $result->toJson(JSON_PRETTY_PRINT));
37-
38-
if (!$this->option('from-file')) {
39-
File::put(storage_path("{$dir}/result-{$now}.php"), $code);
40-
}
27+
$this->log($result, $code);
4128
}
4229

4330
echo $result->toJson();
4431
}
32+
33+
protected function log($result, $code)
34+
{
35+
$dir = 'local-results/detect';
36+
File::ensureDirectoryExists(storage_path($dir));
37+
$now = now()->format('Y-m-d-H-i-s');
38+
39+
File::put(storage_path("{$dir}/result-{$now}.json"), $result->toJson(JSON_PRETTY_PRINT));
40+
41+
if (!$this->option('from-file')) {
42+
File::put(storage_path("{$dir}/result-{$now}.php"), $code);
43+
}
44+
}
4545
}

0 commit comments

Comments
 (0)