Exakat 1.9.9 Review

Exakat focuses on automated updates this week : two new reports (and sections) provide recommendations to use Rector and Php-cs-fixer for fixing, en masse, issues found during an audit. Also, no less than 9 new rules were added to Exakat, and a new inventory for mbstring encoding. 

The Exakat 1.9.9 review is the best interpreter of the source code.

Fixing code automatically

While Exakat focuses on finding the most intricate bugs, other tools are able to fix en masse code. Among such tools, Rector and PHP-cs-fixer are doing a fine job, taking some laborious work from our hands.

Rector offers ‘Instant Upgrades and Instant Refactoring of any PHP 5.3+ code’. It is the masterpiece of Tomas Votruba and a large community. There is an ever-growing list of rectors, which may also be detected with Exakat. From there, Exakat may produce the necessary Rector configuration to fix the code automatically. 

After running an Exakat audit, you may access the Rector configuration in the Ambassador report, in the section called ‘Fixes’. Copy/paste the configuration in your rector.yaml file, and update the code.

You may also invoke the results directly, with the following command : 

php exakat.phar report -p rector -format Rector -v

The PHP-cs-fixer “tool fixes your code to follow standards; whether you want to follow PHP coding standards as defined in the PSR-1, PSR-2, etc., or other community-driven ones like the Symfony one.” It is authored by FriendsOfPHP.

Some of the numerous fixes go beyond simple coding standard, and suggest using Date Immutable instead of Datetime, or help with EREG to PREG migration. A lot of those fixes are also detected by Exakat : a configuration file for PHP-CS-FIXER may be generated, based on the analysis found with Exakat.

After running an Exakat audit, you may access the PHP-CS-FIXER configuration in the Ambassador report, in the section called ‘Fixes’. Copy/paste the configuration in your .php_cs file, and update the code.

You may also invoke the results directly, with the following command : 

php exakat.phar report -p rector -format Phpcsfixer -v

Typhinting Usage and Statistics

Exakat 1.9.9 collects usage statistics for Typehinting.

This cover several questions about typehinting : 

  • The number of methods using typehint
  • Which typehint is used : argument or return (properties will come later)
  • Which definitions use typehint : methods, functions, closures, arrow functions (with php 7.4)
  • which scalar typehints are used

We’re using our test corpus of 1700 applications to collect such information, and we’ll publish a full review later. In the meantime, send us a note if you have some specific information you’d like to know about typehint usage.

From the first results, 25% of PHP code is using type hinting, with 60% of them being scalar. Most common typehint is ‘array’. Figures may change by the end of the survey! 

Encoding inventory

A new inventory has joined the large family of inventories : mbstring encoding. Encoding are used with numerous mbstring functions, such as mb_stripos or mb_strtolower : also, Don’t miss the third arg!

Here, we can see that None is also written NONE, and noneUTF-8 is also named utf8 and utf-8. There is also the ASCII, which is actually named with its alias, us-ascii.

There are other inventories : SQL, dates, formats, Regex, etc. 

The Weekly Audits: 2019, Week #41

Exakat includes a ‘weekly’ report: this report is built with a selection of five analyses. This means a short audit report, with few issues to review. This is not a lot to read them, and review them in your code. Everyone in the PHP community can focus on one of the classic coding problems and fix it. Talk about the weekly audit around you: you’ll find programmers facing the same challenges.

To obtain the ‘weekly’ audit, run an audit, and request the ‘Weekly’ report.

# Init the project (skip when it is already done)    
php exakat.phar init -p <yourproject> -R https://github.com/Seldaek/monolog.git -git 

# Run the project (skip when it is already done)    
php exakat.phar project -p <yourproject> 

# Export the weekly project (every Monday)    
php exakat.phar report -p <yourproject> -format Weekly 

# Open projects/<yourproject>/weekly/index.html in your browser    

Every week, you can find here 5 new analysis to review in your code. In fact, when your code is clean, you can also take a quick look at the upcoming analysis. 

Weekly recommendations for PHP code review : 2019, week 2019-42

Happy PHP Code Reviews 

All the 390 analyzers are presented in the docs, including the mobile : Common Alternatives: in a conditional structure, expressions were found that are common to both ‘then’ and ‘else’.

This is a classic bug, with more than 61% of chance to appear. 

You can check all of the Exakat reports at the gallery: exakat gallery.

Download Exakat on exakat.io, install it with Docker, upgrade it with ‘exakat.phar upgrade -u’ and like us on github.