PHP Classes

How to Measure the PHP Variable Lifetime To Help Developers Improve the Quality of the Code that Uses Variables with the Package PHP Variable Lifetime Analyzer: Analyze the use of variables in a PHP script

Recommend this page to a friend!
     
  Info   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2024-08-05 (2 days ago) RSS 2.0 feedNot yet rated by the usersTotal: 11 This week: 11All time: 11,364 This week: 7Up
Version License PHP version Categories
php-variable-lifetim 1.0.0The PHP License8Tools, Console, PHP 8
Description 

Author

This package can analyze the use of variables in a PHP script.

It provides a tool that can be executed from the command line to analyze a given PHP script.

The tool can generate reports that show in the terminal console the usage of variables during the execution of the script.

Picture of DeGraciaMathieu
  Performance   Level  
Innovation award
Innovation award
Nominee: 13x

Winner: 1x

 

Details

<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 :

  • Average variable lifetime : This represents the average lifetime of variables across the entire project. It includes all variables from all methods and can be influenced by variables with very long lifetimes.
  • Average variable lifetime per method : This is the average of the lifetimes of variables within each method, averaged across all methods. It gives an indication of the average variable lifetime at the method level and is less influenced by extreme values.
  • Max variable lifetime : The maximum lifetime observed for any variable in the project. This value indicates the longest duration any single variable is in scope during the project's execution.

Options

| Options | Description | |-----------------------|-------------| | --json | Output the analysis results in JSON format |

> [!TIP] > Other analysis tools are available.


  Files folder image Files (43)  
File Role Description
Files folder imageapp (5 directories)
Files folder imagearts (1 file)
Files folder imagebootstrap (2 files)
Files folder imageconfig (2 files)
Files folder imagetests (3 files, 2 directories)
Accessible without login Plain text file .editorconfig Data Auxiliary data
Accessible without login Plain text file box.json Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file phpunit.xml.dist Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation
Plain text file variable-lifetime-analyzer Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:11
This week:11
All time:11,364
This week:7Up