Skip to content

Commit cc4c293

Browse files
authored
Merge pull request #4 from smeghead/feature/update-readme
update README.
2 parents 9becb56 + ec032a9 commit cc4c293

File tree

1 file changed

+72
-1
lines changed

1 file changed

+72
-1
lines changed

README.md

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@
33
## Overview
44
This PHP CLI tool analyzes the usage of local variables in PHP source code, focusing on their scope and update frequency. It helps developers identify potential issues in handling local variables, improving code quality and maintainability.
55

6+
## What is "Local Variable Hard Usage"?
7+
"Local Variable Hard Usage" is a concept that evaluates how intensely local variables are used in a function or method. This metric helps identify variables that might negatively impact code readability and maintainability due to excessive scope width and frequent updates.
8+
9+
The idea behind this metric is that when a local variable is referenced over a wide range of lines or is frequently modified, it becomes harder to understand and refactor. By quantifying this, we can gain insights into potential problem areas in the code.
10+
11+
This concept is introduced and explained in detail in the following blog post:
12+
[Understanding Local Variable Hard Usage](https://blog.starbug1.com/archives/3022)
13+
14+
This tool analyzes PHP code using PHP-Parser to measure the "Local Variable Hard Usage" for each function and method. It calculates the average reference line span of each variable and sums the deviations from this average, providing a score that represents how heavily a variable is used within its scope.
15+
16+
617
## Features
718
- Analyzes local variable scope and update frequency.
819
- Provides insights into variable usage patterns.
@@ -11,4 +22,64 @@ This PHP CLI tool analyzes the usage of local variables in PHP source code, focu
1122
## Installation
1223
To install the PHP CLI tool, follow these steps:
1324

14-
1. Clone the repository:
25+
1. Clone the repository:
26+
```sh
27+
git clone https://github.com/smeghead/php-variable-hard-usage.git
28+
cd php-variable-hard-usage
29+
```
30+
31+
2. Install dependencies using Composer:
32+
```sh
33+
composer install
34+
```
35+
36+
Alternatively, you can install the tool via Composer as a development dependency:
37+
```sh
38+
composer require --dev smeghead/php-variable-hard-usage
39+
```
40+
41+
## Usage
42+
43+
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.
44+
45+
```bash
46+
$ vendor/bin/php-variable-hard-usage somewhere/your-php-file.php
47+
{
48+
"maxVariableHardUsage": 65,
49+
"avarageVariableHardUsage": 26.833333333333332,
50+
"scopes": [
51+
{
52+
"namespace": "Smeghead\\PhpVariableHardUsage\\Parse",
53+
"name": "VariableParser::__construct",
54+
"variableHardUsage": 1
55+
},
56+
{
57+
"namespace": "Smeghead\\PhpVariableHardUsage\\Parse",
58+
"name": "VariableParser::resolveNames",
59+
"variableHardUsage": 9
60+
},
61+
{
62+
"namespace": "Smeghead\\PhpVariableHardUsage\\Parse",
63+
"name": "VariableParser::parse",
64+
"variableHardUsage": 39
65+
},
66+
{
67+
"namespace": "Smeghead\\PhpVariableHardUsage\\Parse",
68+
"name": "Expr_ArrowFunction@49",
69+
"variableHardUsage": 0
70+
},
71+
{
72+
"namespace": "Smeghead\\PhpVariableHardUsage\\Parse",
73+
"name": "VariableParser::collectParseResultPerFunctionLike",
74+
"variableHardUsage": 65
75+
},
76+
{
77+
"namespace": "Smeghead\\PhpVariableHardUsage\\Parse",
78+
"name": "Expr_Closure@65",
79+
"variableHardUsage": 47
80+
}
81+
]
82+
}
83+
```
84+
85+

0 commit comments

Comments
 (0)