Skip to content

Commit a888e16

Browse files
committed
Merge branch 'windows-binary'
2 parents 9f9ae16 + 0926719 commit a888e16

File tree

4 files changed

+57
-35
lines changed

4 files changed

+57
-35
lines changed

app/Commands/AutocompleteCommand.php

+17-19
Original file line numberDiff line numberDiff line change
@@ -8,41 +8,39 @@
88

99
class AutocompleteCommand extends Command
1010
{
11-
protected $signature = 'autocomplete {code} {--debug} {--from-file=}';
11+
use ResolvesCode;
12+
13+
protected $signature = 'autocomplete {code} {--from-file} {--debug} {--local-file=}';
1214

1315
protected $description = 'Parse the given PHP code and return the autocomplete results';
1416

1517
public function handle(): void
1618
{
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');
2220

2321
$walker = new Walker($code, (bool) $this->option('debug'));
2422
$result = $walker->walk();
2523

2624
$autocompleting = $result->findAutocompleting();
2725

2826
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);
3928
}
4029

4130
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');
4238

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+
}
4542

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));
4745
}
4846
}

app/Commands/DetectCommand.php

+18-15
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,36 @@
88

99
class DetectCommand extends Command
1010
{
11-
protected $signature = 'detect {code} {--debug} {--from-file=}';
11+
use ResolvesCode;
12+
13+
protected $signature = 'detect {code} {--from-file} {--debug} {--local-file=}';
1214

1315
protected $description = 'Detect things we care about in the current code';
1416

1517
public function handle(): void
1618
{
17-
$code = $this->argument('code');
18-
19-
if ($this->option('from-file')) {
20-
$code = file_get_contents(__DIR__ . '/../../tests/snippets/detect/' . $this->option('from-file') . '.php');
21-
}
19+
$code = $this->resolveCode('detect');
2220

2321
$walker = new DetectWalker($code, (bool) $this->option('debug'));
2422
$result = $walker->walk();
2523

2624
if (app()->isLocal()) {
27-
$dir = 'local-results/detect';
28-
File::ensureDirectoryExists(storage_path($dir));
29-
$now = now()->format('Y-m-d-H-i-s');
30-
31-
File::put(storage_path("{$dir}/result-{$now}.json"), $result->toJson(JSON_PRETTY_PRINT));
32-
33-
if (!$this->option('from-file')) {
34-
File::put(storage_path("{$dir}/result-{$now}.php"), $code);
35-
}
25+
$this->log($result, $code);
3626
}
3727

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

app/Commands/ResolvesCode.php

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace App\Commands;
4+
5+
trait ResolvesCode
6+
{
7+
protected function resolveCode($path): string
8+
{
9+
if ($this->option('local-file')) {
10+
return file_get_contents(__DIR__ . '/../../tests/snippets/' . $path . '/' . $this->option('from-file') . '.php');
11+
}
12+
13+
$code = $this->argument('code');
14+
15+
if ($this->option('from-file')) {
16+
return file_get_contents($code);
17+
}
18+
19+
return $code;
20+
}
21+
}

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"homepage": "https://laravel-zero.com",
1212
"type": "project",
1313
"license": "MIT",
14-
"version": "0.1.28",
14+
"version": "0.1.33",
1515
"support": {
1616
"issues": "https://github.com/laravel-zero/laravel-zero/issues",
1717
"source": "https://github.com/laravel-zero/laravel-zero"

0 commit comments

Comments
 (0)