Home

Awesome

<p align="center"> <img src="https://github.com/DeGraciaMathieu/php-smelly-code-detector/blob/master/arts/robot.png" width="250"> </p>

php-variable-lifetime-analyzer

The lifetime of a variable represents the time a variable exists in a script. It is calculated from the first line to the last line using a given variable.

Favoring variables with a short lifetime can improve code readability and help prevent potential errors. A variable with a long lifetime will likely span from one end of your script to the other, making it difficult to understand. This tool helps monitor the lifetime of your variables and ensures they are placed as close to their usage as possible.

<p align="center"> <img src="/arts/logo.png" width="600"> </p>

Phar

This tool is distributed as a PHP Archive (PHAR):

wget https://github.com/DeGraciaMathieu/php-variable-lifetime-analyzer/raw/main/builds/variable-lifetime-analyzer
php variable-lifetime-analyzer --version

Usage

php variable-lifetime-analyzer analyze {path}

Example

php variable-lifetime-analyzer analyze app

 ❀ PHP Var Lifetime Analyzer ❀

 117 files found.

 392 variables found.

 ┌───────────────────────────┬──────────────────────────────────────┬───────────────────────┐
 │ Average variable lifetime │ Average variable lifetime per method │ Max variable lifetime │
 ├───────────────────────────┼──────────────────────────────────────┼───────────────────────┤
 │ 2.18                      │ 1.61                                 │ 22.00                 │
 └───────────────────────────┴──────────────────────────────────────┴───────────────────────┘

Understanding analysis :

Options

OptionsDescription
--jsonOutput the analysis results in JSON format

[!TIP]
Other analysis tools are available.