-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCommand.php
More file actions
47 lines (40 loc) · 1.2 KB
/
Command.php
File metadata and controls
47 lines (40 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
declare(strict_types=1);
namespace Smeghead\PhpVariableHardUsage;
use Smeghead\PhpVariableHardUsage\Analyze\VariableAnalyzer;
use Smeghead\PhpVariableHardUsage\Parse\VariableParser;
final class Command
{
/**
* @param list<string> $argv
*/
public function run(array $argv): void
{
if (count($argv) < 2) {
$this->printHelp();
return;
}
$filePath = $argv[1];
if (!file_exists($filePath)) {
echo "File not found: $filePath\n";
return;
}
$parser = new VariableParser();
$content =file_get_contents($filePath);
if ($content === false) {
echo "Failed to read file: $filePath\n";
return;
}
$parseResult = $parser->parse($content);
$analyzer = new VariableAnalyzer($filePath, $parseResult->functions);
$result = $analyzer->analyze();
echo $result->format();
}
private function printHelp(): void
{
echo "Usage: php bin/php-variable-hard-usage [source_file]\n";
echo "Options:\n";
echo " --help Display help information\n";
echo " --version Show the version of the tool\n";
}
}