File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11# CHANGELOG
22
3+ ### Features
4+
5+ * Added subcommand support with ` single ` and ` scopes ` modes
6+ * The ` single ` mode analyzes a single PHP file
7+ * The ` scopes ` mode supports analyzing multiple files and directories
8+ * Enhanced command line interface with help and version options
9+
310## v0.0.3 (2025-03-20)
411
512### Features
Original file line number Diff line number Diff line change @@ -34,7 +34,8 @@ private function analyzeFunction(Func $function): Scope
3434 $ analyzedVars = [];
3535
3636 foreach ($ variableNames as $ variableName ) {
37- $ vars = array_filter ($ variables , fn ($ variable ) => $ variable ->name === $ variableName );
37+ // array_values でインデックスを振り直す
38+ $ vars = array_values (array_filter ($ variables , fn ($ variable ) => $ variable ->name === $ variableName ));
3839 $ variableHardUsage = $ this ->calcVariableHardUsage ($ vars );
3940 $ analyzedVars [] = new AnalyzedVariable ($ variableName , $ variableHardUsage );
4041 }
Original file line number Diff line number Diff line change @@ -17,10 +17,10 @@ protected function printHelp(): void
1717 {
1818 echo "Usage: php bin/php-variable-hard-usage [command] [options] \n" ;
1919 echo "Commands: \n" ;
20- echo " single <file> Analyze a single file \n" ;
21- echo " scopes <directory> Analyze PHP files in a directory \n" ;
20+ echo " single <file> Analyze a single file \n" ;
21+ echo " scopes <path1> [<path2> ...] Analyze PHP files in directories or specific files \n" ;
2222 echo "Options: \n" ;
23- echo " --help Display help information \n" ;
24- echo " --version Show the version of the tool \n" ;
23+ echo " --help Display help information \n" ;
24+ echo " --version Show the version of the tool \n" ;
2525 }
2626}
Original file line number Diff line number Diff line change 99
1010final class ScopesCommand extends AbstractCommand
1111{
12- private string $ directory ;
12+ /** @var list<string> */
13+ private array $ paths ;
1314
14- public function __construct (string $ directory )
15+ /**
16+ * @param list<string> $paths ディレクトリまたはファイルのパスリスト
17+ */
18+ public function __construct (array $ paths )
1519 {
16- $ this ->directory = $ directory ;
20+ $ this ->paths = $ paths ;
1721 }
1822
1923 public function execute (): void
2024 {
21- if (!is_dir ($ this ->directory )) {
22- fwrite (STDERR , "Directory not found: {$ this ->directory }\n" );
23- return ;
25+ $ phpFiles = [];
26+
27+ // 各パスを処理
28+ foreach ($ this ->paths as $ path ) {
29+ if (is_dir ($ path )) {
30+ // ディレクトリの場合は再帰的にPHPファイルを収集
31+ $ dirFiles = $ this ->findPhpFiles ($ path );
32+ $ phpFiles = array_merge ($ phpFiles , $ dirFiles );
33+ } elseif (is_file ($ path ) && pathinfo ($ path , PATHINFO_EXTENSION ) === 'php ' ) {
34+ // 単一のPHPファイルの場合
35+ $ phpFiles [] = $ path ;
36+ } else {
37+ fwrite (STDERR , "Invalid path: {$ path }\n" );
38+ }
2439 }
2540
26- $ phpFiles = $ this ->findPhpFiles ($ this ->directory );
2741 if (empty ($ phpFiles )) {
28- fwrite (STDERR , "No PHP files found in: { $ this -> directory } \n" );
42+ fwrite (STDERR , "No PHP files found in specified paths \n" );
2943 return ;
3044 }
3145
46+ // 重複を削除
47+ $ phpFiles = array_unique ($ phpFiles );
48+
3249 $ results = [];
3350 foreach ($ phpFiles as $ file ) {
3451 try {
Original file line number Diff line number Diff line change @@ -41,10 +41,11 @@ public function createCommand(array $argv): CommandInterface
4141
4242 if ($ arg === 'scopes ' ) {
4343 if (count ($ argv ) < 3 ) {
44- fwrite (STDERR , "Usage: php bin/php-variable-hard-usage scopes <directory> \n" );
44+ fwrite (STDERR , "Usage: php bin/php-variable-hard-usage scopes <path1> [<path2> ...] \n" );
4545 return new HelpCommand ();
4646 }
47- return new ScopesCommand ($ argv [2 ]);
47+ // 複数のパスを渡す
48+ return new ScopesCommand (array_slice ($ argv , 2 ));
4849 }
4950
5051 // 後方互換性のため、コマンドが指定されていない場合は単一ファイルモードとして扱う
You can’t perform that action at this time.
0 commit comments