In this article, we are going to see how some tools & libraries will make people's lives easier during the development & code review process.
And 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 PHP codesniffer and Drupal coder module.
If you are maintaining your code in Github, then Github is providing continuous integration support within their workflows.
It's pretty simple, if we already know PHPCS and PHPCBF libraries are used to do the code reviews and checks on your local machines and the same thing can be done once the pull request is raised by the developer.
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
.github/workflows/ci.yml
Add the below code to the ci.yml
file.
name: pr-review
on: [pull_request]
jobs:
check-drupal-code-standards:
runs-on: ubuntu-latest
steps:
- name: Install PHPCS
run: composer global require –dev drupal/coder dealerdirect/php codesniffer-composer-installer
- name: Clone code
run: actions/checkout@v3
- name: Check drupal coding standards
run: ~/.composer/vendor/bin/phpcs –standard=”Drupal,DrupalPractice” –extensions=”php,module,inc,install,test,profile,theme,css,info”
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 3 steps
- To install PHPCS
- To clone the code
- To run the phpcs checks (like we run locally)
Once this 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.