PHP Classes

File: README.md

Recommend this page to a friend!
  Classes of DeGraciaMathieu   PHP Variable Lifetime Analyzer   README.md   Download  
File: README.md
Role: Documentation
Content type: text/markdown
Description: Documentation
Class: PHP Variable Lifetime Analyzer
Analyze the use of variables in a PHP script
Author: By
Last change:
Date: 17 days ago
Size: 3,208 bytes
 

Contents

Class file image Download

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