Skip to content

Commit 4e6daf7

Browse files
committed
fix: The explanation of the calculation specification for local variable severity has been corrected.
1 parent c24feb8 commit 4e6daf7

1 file changed

Lines changed: 15 additions & 13 deletions

File tree

README.md

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -84,40 +84,42 @@ $ vendor/bin/php-variable-hard-usage somewhere/your-php-file.php
8484
}
8585
```
8686

87+
8788
## How to calculate VariableHardUsage
8889

89-
VariableHardUsage is an index used to evaluate the frequency of use and scope of a local variable within a function. This indicator is calculated based on the variance of the line number at which the variable is used and the frequency with which the variable is assigned.
90+
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.
9091

9192
### Calculation Procedure
9293

93-
1. Obtain the line numbers of the variables:.
94+
1. Obtain the line numbers of the references to the same variable:.
9495

95-
* Obtains the line numbers of all variables used in the function.
96+
* For each variable used in the function, retrieve all line numbers where the variable is referenced.
9697

9798
2. Calculate the average of the line numbers.
9899

99-
* Calculates the average of the retrieved line numbers. This is obtained by dividing the sum of the line numbers by the number of variables.
100+
* Calculates the average of the line numbers obtained. This is obtained by dividing the sum of the line numbers by the number of references.
100101

101102
3. Calculate VariableHardUsage.
102103

103-
* For each variable, the absolute difference between the line number and the average line number is calculated.
104+
* Calculates the absolute difference between the line number and the average line number for each reference.
104105
* If a variable is assigned, the difference is multiplied by a factor (2 by default).
105106
* Sum all these values to obtain VariableHardUsage.
106107

107-
### EXAMPLE.
108+
### Example
108109

109-
For example, suppose there are three variables in a function, each with row numbers 10, 20, and 30, and that some assignments are made and some are not made. In this case, the average row number is 20.
110+
For example, suppose there are three reference points in a function, each with line numbers 10, 20, and 30, where some assignments are made and some are not made. In this case, the average row number is 20.
110111

111-
* Variable A: Row 10, with assignment
112-
* Variable B: Row 20, no assignment
113-
* Variable C: Row 30, with assignment
112+
* Reference A: Row 10, with assignment
113+
* Reference B: Row 20, no assignment
114+
* Reference C: Row 30, with assignment
114115

115116
In this case, VariableHardUsage is calculated as follows
116117

117-
* Variable A: |10 - 20| * 2 = 20
118-
* Variable B: |20 - 20| * 1 = 0
119-
* Variable C: |30 - 20| * 2 = 20
118+
* Reference A: |10 - 20| * 2 = 20
119+
* Reference B: |20 - 20| * 1 = 0
120+
* Reference C: |30 - 20| * 2 = 20
120121

121122
Summing these, VariableHardUsage is 20 + 0 + 20 = 40.
122123

123124
VariableHardUsage is thus calculated as a measure of the frequency of use and scope of a variable. This metric can be used to quantitatively evaluate the usage of local variables within a function and help improve code readability and maintainability.
125+

0 commit comments

Comments
 (0)