7 Laravel Packages to Improve Coding Standards and Reduce Bugs
Tags: laravel, php, webdev, beginners
Published: 2022-08-01 15:52:33

Packages to analyse coding standards and reduce bugs

Frustrated with fixing the same kind of issues and spending more time to improve your App coding standard? This is a common issue for larger apps with more number developers working on it. We spend more time maintaining the coding standard across the team and reducing bugs, To make this simple we have a few packages to automate these.

As we all know, the [Laravel](https://laravel.com/) community is growing rapidly daily, and the packages developed for Laravel are also increasing. We will look into a few packages in this article to improve PHP coding standards and automate some tasks that were done manually.


## Larastan

![larastan](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lqomhmo9sx42hfyrad3s.png)

[Larastan](https://github.com/nunomaduro/larastan) is a Coding Standards Fixer tool, It's a [PHPStan](https://phpstan.org/) wrapper for Laravel. Larastan focuses on finding errors in your code. It catches whole classes of bugs even before you write tests for the code.

### Highlights

1. Adds static typing to Laravel to improve developer productivity and code quality.
2. Supports most of Laravel's magic methods.
3. Discovers bugs in your code.

**Github - 4.1K ⭐️**


## PHPStan

[PHPStan](https://github.com/phpstan/phpstan) is a static code analysis tool, It focuses on finding errors in your code without actually running it. It catches whole classes of bugs even before you write tests for the code. It moves PHP closer to compiled languages in the sense that the correctness of each line of the code can be checked before you run the actual code.

### Highlights

1. Find bugs before they reach production.
2. Gradual Integration
3. Legacy compatibility
4. Third-party framework integrations


![phpstan](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1nqs1880wfltwf9oc14s.png)

**Github - 11.2K ⭐️**


## PHP CodeSniffer

[PHP CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer) is also a coding standard tool. It tokenizes PHP files and detects violations of a defined set of coding standards. 

PHP CpdeSniffer is a set of two PHP scripts. The main `phpcs` script tokenizes PHP, JavaScript and CSS files to detect violations of a defined coding standard, and a second `phpcbf` script automatically corrects coding standard violations. PHP CodeSniffer is an essential development tool that ensures your code remains clean and consistent.

![php-sniffer](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k6fqwem6szt8k7zky1k3.png)

**Github - 9.6K ⭐️**


## Phan

[Phan](https://github.com/phan/phan) is a static analyzer for PHP. Phan prefers to avoid false positives and attempts to prove incorrectness rather than correctness. 

Phan looks for common issues and will verify type compatibility on various operations when type information is available or can be deduced. Phan has a good understanding of flow control and can track values in a few use cases (e.g. arrays, integers, and strings).

**Github - 5.3K ⭐️**


## PHP Inspections

![inspection-php](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5wfgrdcqwu1z53vwtgoi.png)

[PHP Inspections](https://github.com/kalessil/phpinspectionsea) is a static code analyzer and code review tool for PhpStorm IDE.
 
### Highlights

1. Architecture related issues
2. Weak types of control and possible code construct simplifications
3. Performance issues
4. Validation of magic methods usage
5. Validation of exception handling workflow
6. Compatibility issues
7. Variety of time-consuming bugs
8. Security issues

**Github - 1.3K ⭐️**


## PHP Insights

![php-insights](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vyyca8g0yjwlxrapfmep.png)

[PHP Insights](https://github.com/nunomaduro/phpinsights) is a static analysis tool of your code directly from your terminal. By running a single command it displays the Quality of Code, Complexity of Code, Architecture and Coding Style.

### Highlights

1. Analysis of code quality and coding style
2. Beautiful overview of code architecture and its complexity
3. Designed to work out-of-the-box with Laravel, Symfony, Yii, Magento, and more
4. Contains built-in checks for making code reliable, loosely coupled, simple, and clean.

![terminal-insights](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e5zrvolgouoquv4zwd6l.png)

**Github - 4.7K ⭐️**

## PEST


![pest](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qt691mt9tw0qr9j6j2v6.png)

[Pest](https://github.com/pestphp/pest) is an elegant PHP Testing Framework with a focus on simplicity. It has a good interface to display test results and easily understandable APIs to write tests. 

Pest also has [IDE plugins](https://pestphp.com/docs/ide-plugins) for PHP Strom and VS Code.

![pest-terminal](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3ffz0odr8q3ngdve53nn.png)

**Github - 5.1K ⭐️**

## Laravel Pint


![pint](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m6nld49qvwsg8ql1f479.png)

[Laravel Pint](https://github.com/laravel/pint) is an opinionated PHP code style fixer for minimalists. Pint is built on top of [PHP-CS-Fixer](https://github.com/FriendsOfPHP/PHP-CS-Fixer) and makes it simple to ensure that your code style stays clean and consistent. Pint is a new addition to the [Laravel framework](https://laravel.com/docs/9.x/pint#introduction). 

It will be available pre-installed on fresh installs.
By default, Pint does not require any configuration and will fix code style issues in your code by following the opinionated coding style of Laravel.

![pint-terminal](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z7v8mnmnd0dpijaubpqx.png)

**Github - 2K ⭐️**


## Conclusion

There are multiple open source tools to maintain coding standards and reduce bugs in Laravel. Choose a tool from above that best fits your project and environment.

Thank you for reading.

Get more updates on [Twitter](https://twitter.com/Nilanth).

**You can support me [by buying me a coffee](https://buymeacoffee.com/nilanth) ☕**

## eBook

[Debugging ReactJS Issues with ChatGPT: 50 Essential Tips and Examples](https://nilanth.gumroad.com/l/ztehh)

[ReactJS Optimization Techniques and Development Resources](https://nilanth.gumroad.com/l/NYkdN)

## More Blogs
1. [Use Vite for React Apps instead of CRA]
(https://dev.to/nilanth/use-vite-for-react-apps-instead-of-cra-3pkg)
2. [Twitter Followers Tracker using Next.js, NextAuth and TailwindCSS](https://dev.to/nilanth/twitter-followers-tracker-using-nextjs-nextauth-and-tailwindcss-1em7)
3. [Don't Optimize Your React App, Use Preact Instead
](https://dev.to/nilanth/dont-optimize-your-react-app-use-preact-instead-30og)
4. [How to Reduce React App Loading Time By 70%](https://dev.to/nilanth/how-to-reduce-react-app-loading-time-by-70-1kmm)
5. [Build a Portfolio Using Next.js, Tailwind, and Vercel with Dark Mode Support](https://dev.to/nilanth/build-a-portfolio-using-next-js-tailwind-and-vercel-4dd8)
6. [No More ../../../ Import in React](https://dev.to/nilanth/no-more-import-in-react-2mbo)
7. [10 React Packages with 1K UI Components
](https://dev.to/nilanth/10-react-packages-with-1k-ui-components-2bf3)
8. [5 Packages to Optimize and Speed Up Your React App During Development](https://dev.to/nilanth/5-packages-to-optimize-and-speed-up-your-react-app-during-development-4h5f)
9. [How To Use Axios in an Optimized and Scalable Way With React](https://dev.to/nilanth/how-to-use-axios-in-an-optimized-and-scalable-way-with-react-518n)
10. [15 Custom Hooks to Make your React Component Lightweight](https://dev.to/nilanth/15-custom-hooks-to-make-your-react-component-lightweight-17cd)
11. [10 Ways to Host Your React App For Free](https://dev.to/nilanth/10-ways-to-host-your-react-app-for-free-27ga)
12. [How to Secure JWT in a Single-Page Application](https://dev.to/nilanth/how-to-secure-jwt-in-a-single-page-application-cko)