This is LARA Nepal. X

Php Insights: Your Code Quality Companion

Published on May 4, 2024 by

PHP Insights: Your Code Quality Companion

Mastering Advance PHP Automated Tooling

Are you looking to enhance the quality of your PHP code effortlessly? Let's explore some automated tools that can aid in auditing your code and identifying areas for improvement. In this guide, we'll walk through the tools I commonly use and how to interpret their findings. Although these tools may offer overlapping features and analyses, each brings its own unique checks to the table, providing a comprehensive audit experience.

PHP Insights: Your Code Quality Companion

PHP Insights

PHP Insights emerges as a versatile tool tailored to uplift your PHP projects' code quality. Crafted by Nuno Maduro, with design by Caneco, and currently maintained by Chris Gmyr, Jibé Barth, and Steve McDougall, PHP Insights stands out with its array of built-in checks. It facilitates the creation of reliable, loosely coupled, simple, and clean code. Notably, PHP Insights seamlessly integrates with frameworks like Laravel, Symfony, WordPress, and more, extending its utility beyond Laravel projects.

At the time of writing, PHP Insights gives you insights into 4 distinct categories:

  • Code (105 insights)
  • Architecture (20 insights)
  • Complexity (1 insight)
  • Style (84 insights)

The results that PHP Insights generates are also presented in a nice, easy-to-read format in your terminal after running. After the command has run, you'll be presented with an overview of the results like so: Automation Tool

Installation

To get started, we'll first need to install PHP Insights using the following command:

composer require nunomaduro/phpinsights --dev

After that, you can publish the package's config file using the following command:

php artisan vendor:publish --provider="NunoMaduro\PhpInsights\Application\Adapters\Laravel\InsightsServiceProvider"

Analysing Your Code with PHP Insights

That's it! You should now be ready to run PHP Insights using the following command:

php artisan insights

Running the command above will analyse your entire codebase. However, if you'd prefer to only analyse a specific file or directory, you can pass a path to the insights Artisan command. For example, if we only wanted to analyse the code in our app/Http/Controllers directory, we could run the following command:

php artisan insights app/Http/Controllers

Or for example, if we wanted to analyse a specific controller (such as app/Http/Controllers/UserController.php), we could run the following command:

php artisan insights app/Http/Controllers/UserController.php

Note for Laravel 7 users: phpinsights requires PHP 7.3+, and PHPUnit 9.0+. For upgrading PHPUnit, you can use following command:

composer require --dev phpunit/phpunit:^9.0 --update-with-dependencies

Conclusion

Elevate PHP project quality effortlessly. PHP Insights offers comprehensive code auditing, seamlessly integrating with Laravel and other frameworks. Streamline analysis, make informed decisions, and enhance code maintainability today.

Discussion

Login or register to comment or ask questions

No comments or questions yet...