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  
Name: DeGraciaMathieu <contact>
Classes: 19 packages by
Country: France France
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

  Files folder image Files (43)  /  app  
File Role Description
Files folder imageApplication (4 files)
Files folder imageDomain (5 directories)
Files folder imageInfrastructure (5 directories)
Files folder imagePresenter (1 directory)
Files folder imageProviders (1 file)

  Files folder image Files (43)  /  app  /  Application  
File Role Description
  Plain text file AnalyzeAction.php Class Class source
  Plain text file AnalyzeInput.php Class Class source
  Plain text file AnalyzeOutput.php Class Class source
  Plain text file AnalyzeResponse.php Class Class source

  Files folder image Files (43)  /  app  /  Domain  
File Role Description
Files folder imageAggregators (2 files)
Files folder imageDataTransferObjects (1 file)
Files folder imageEntities (5 files)
Files folder imagePorts (2 files)
Files folder imageValueObjects (2 files)

  Files folder image Files (43)  /  app  /  Domain  /  Aggregators  
File Role Description
  Plain text file AnalyzeAggregator.php Class Class source
  Plain text file FileAggregator.php Class Class source

  Files folder image Files (43)  /  app  /  Domain  /  DataTransferObjects  
File Role Description
  Plain text file Path.php Class Class source

  Files folder image Files (43)  /  app  /  Domain  /  Entities  
File Role Description
  Plain text file Analyze.php Class Class source
  Plain text file ClassAnalyze.php Class Class source
  Plain text file File.php Class Class source
  Plain text file MethodAnalyze.php Class Class source
  Plain text file NullAnalyze.php Class Class source

  Files folder image Files (43)  /  app  /  Domain  /  Ports  
File Role Description
  Plain text file AnalyzerService.php Class Class source
  Plain text file FileRepository.php Class Class source

  Files folder image Files (43)  /  app  /  Domain  /  ValueObjects  
File Role Description
  Plain text file Fqcn.php Class Class source
  Plain text file Variable.php Class Class source

  Files folder image Files (43)  /  app  /  Infrastructure  
File Role Description
Files folder imageFactories (2 files)
Files folder imageHelpers (1 file)
Files folder imageRepositories (1 file)
Files folder imageServices (1 file)
Files folder imageVisitors (1 file)

  Files folder image Files (43)  /  app  /  Infrastructure  /  Factories  
File Role Description
  Plain text file FileFactory.php Class Class source
  Plain text file VariableFactory.php Class Class source

  Files folder image Files (43)  /  app  /  Infrastructure  /  Helpers  
File Role Description
  Plain text file NodeHelper.php Class Class source

  Files folder image Files (43)  /  app  /  Infrastructure  /  Repositories  
File Role Description
  Plain text file FileRepositoryAdapter.php Class Class source

  Files folder image Files (43)  /  app  /  Infrastructure  /  Services  
File Role Description
  Plain text file AnalyzerServiceAdapter.php Class Class source

  Files folder image Files (43)  /  app  /  Infrastructure  /  Visitors  
File Role Description
  Plain text file VarLifetimeVisitor.php Class Class source

  Files folder image Files (43)  /  app  /  Presenter  
File Role Description
Files folder imageCommands (3 files)

  Files folder image Files (43)  /  app  /  Presenter  /  Commands  
File Role Description
  Plain text file AnalyzeCommand.php Class Class source
  Plain text file JsonAnalyzeOutput.php Class Class source
  Plain text file TerminalAnalyzeOutput.php Class Class source

  Files folder image Files (43)  /  app  /  Providers  
File Role Description
  Plain text file AppServiceProvider.php Class Class source

  Files folder image Files (43)  /  arts  
File Role Description
  Accessible without login Image file logo.png Icon Icon image

  Files folder image Files (43)  /  bootstrap  
File Role Description
  Accessible without login Plain text file app.php Example Example script
  Plain text file providers.php Class Class source

  Files folder image Files (43)  /  config  
File Role Description
  Plain text file app.php Class Class source
  Plain text file commands.php Class Class source

  Files folder image Files (43)  /  tests  
File Role Description
Files folder imageFeature (1 file)
Files folder imageUnit (1 file)
  Plain text file CreatesApplication.php Class Class source
  Plain text file Pest.php Class Class source
  Plain text file TestCase.php Class Class source

  Files folder image Files (43)  /  tests  /  Feature  
File Role Description
  Accessible without login Plain text file InspireCommandTest.php Example Example script

  Files folder image Files (43)  /  tests  /  Unit  
File Role Description
  Accessible without login Plain text file ExampleTest.php Example Example script

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