In this article, we are going to see how some tools & libraries will make people's lives easier during the development and code review process. We have a similar helpful article related to Phpcs, have a check of this.
To make developer life easier, developers look for tools or libraries which can automated code review and if needed make any corrections in the code automatically. Here comes the PhpStan, a static analysing tool which primarily focuses on finding errors in your code without actually running.
If you are maintaining your code in Github, then Github is providing continuous integration support within their workflows.
We could run this locally as well by having the PhpStan library, which will help developers to make sure none of the issues will go to the higher environment.
Also, having the code standard checks done at this level (on PR create level), will ensure the project is maintained with proper drupal coding standards.
To do this, you need to create a folder structure like
.github/workflows within your project (if not created) and Create a file
ci.yml within the folder, once created the file path will look as seen below
Add the below code to the
- name: Clone the code
- name: Setup PHP 7.4
- name: Composer install
run: composer install
- name: Analyse codebase
run: ./vendor/bin/phpstan analyse ./web/modules/custom
The YML file is configured to trigger a job upon the pull request creation.
- Where this job run’s on the Ubuntu machine.
- This job has 4 steps
- To clone the code
- To setup the php 7.4 version.
- To run the composer install
- To run the phpstan checks (like we run locally)
ci.yml is pushed to your github repository, then from next time onwards if any PR is created then this automatic checks will be triggered and will show the pass or fail data on the PR itself.
By this, One level of coding standard check is performed before you push the code to master branch or branch which has the stable code.