Skip to content

Commit b7fee65

Browse files
committed
v0.0.4
1 parent d8acb68 commit b7fee65

File tree

3 files changed

+61
-9
lines changed

3 files changed

+61
-9
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# CHANGELOG
22

3+
## v0.0.4 (2025-03-20)
4+
35
### Features
46

57
* Added subcommand support with `single` and `scopes` modes

README.md

Lines changed: 58 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,16 @@ composer require --dev smeghead/php-variable-hard-usage
4242

4343
## Usage
4444

45-
If you specify the path of the file for which you want to measure the local variable abuse and run the program, a report will be displayed in JSON format.
45+
The tool provides two operation modes: `single` mode for analyzing individual files and `scopes` mode for analyzing multiple files or directories.
46+
47+
### Single File Analysis
48+
49+
Use the `single` command to analyze a single PHP file:
4650

4751
```bash
48-
$ vendor/bin/php-variable-hard-usage somewhere/your-php-file.php
52+
$ vendor/bin/php-variable-hard-usage single path/to/your-file.php
4953
{
54+
"filename": "path/to/your-file.php",
5055
"maxVariableHardUsage": 65,
5156
"avarageVariableHardUsage": 26.833333333333332,
5257
"scopes": [
@@ -64,26 +69,71 @@ $ vendor/bin/php-variable-hard-usage somewhere/your-php-file.php
6469
"namespace": "Smeghead\\PhpVariableHardUsage\\Parse",
6570
"name": "VariableParser::parse",
6671
"variableHardUsage": 39
67-
},
68-
{
69-
"namespace": "Smeghead\\PhpVariableHardUsage\\Parse",
70-
"name": "Expr_ArrowFunction@49",
71-
"variableHardUsage": 0
72-
},
72+
}
73+
]
74+
}
75+
```
76+
77+
For backward compatibility, you can also run without specifying the `single` command:
78+
79+
```bash
80+
$ vendor/bin/php-variable-hard-usage path/to/your-file.php
81+
```
82+
83+
### Multiple Files Analysis
84+
85+
Use the scopes command to analyze multiple files or entire directories:
86+
87+
```bash
88+
# Analyze all PHP files in a directory
89+
$ vendor/bin/php-variable-hard-usage scopes src/
90+
91+
# Analyze multiple directories
92+
$ vendor/bin/php-variable-hard-usage scopes src/ tests/
93+
94+
# Analyze specific files and directories
95+
$ vendor/bin/php-variable-hard-usage scopes src/Command.php config/ tests/
96+
```
97+
98+
The output for scopes mode is a combined report with results sorted by variable hard usage:
99+
100+
```json
101+
{
102+
"scopes": [
73103
{
104+
"file": "src/Parse/VariableParser.php",
74105
"namespace": "Smeghead\\PhpVariableHardUsage\\Parse",
75106
"name": "VariableParser::collectParseResultPerFunctionLike",
76107
"variableHardUsage": 65
77108
},
78109
{
110+
"file": "src/Parse/VariableParser.php",
79111
"namespace": "Smeghead\\PhpVariableHardUsage\\Parse",
80112
"name": "Expr_Closure@65",
81113
"variableHardUsage": 47
114+
},
115+
{
116+
"file": "src/Parse/VariableParser.php",
117+
"namespace": "Smeghead\\PhpVariableHardUsage\\Parse",
118+
"name": "VariableParser::parse",
119+
"variableHardUsage": 39
82120
}
83121
]
84122
}
85123
```
86124

125+
### Help and Version Information
126+
127+
To display help information:
128+
129+
```bash
130+
$ vendor/bin/php-variable-hard-usage --help
131+
```
132+
133+
```bash
134+
$ vendor/bin/php-variable-hard-usage --version
135+
```
136+
87137
## How to calculate VariableHardUsage
88138

89139
VariableHardUsage is an index used to evaluate the frequency of use and scope of local variables within a function. This measure is calculated based on the variance of the line number of references to the same variable and the frequency with which the variable is assigned.

src/Command/AbstractCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
abstract class AbstractCommand implements CommandInterface
88
{
9-
private const VERSION = '0.0.3';
9+
private const VERSION = '0.0.4';
1010

1111
protected function printVersion(): void
1212
{

0 commit comments

Comments
 (0)