Subscribe To Our NewsLetter
Share This Post:
PSRs is a PHP specification published by the PHP Framework Interop Group. It serves the standardization of programming concepts in PHP. The aim is to enable interoperability among components like frameworks, libraries, & projects.
Understanding of PHP Standard Recommendation (PSR):
The PSRs encompass different facets of PHP development, covering coding style, autoloading, coding standards, and HTTP message interfaces. Among the frequently cited PSRs are PSR-1, PSR-2, PSR-4, PSR-7, and PSR-12.
- PSR-1 sets forth fundamental coding standards that include conventions for file naming, class naming, and method naming to ensure consistency and enhance readability.
- PSR-2 builds upon PSR-1 by providing guidelines for indentation, whitespace usage, and control structure formatting, fostering project uniformity.
- PSR-4 simplifies autoloading by defining a standard for PHP class autoload from file paths, thereby enhancing code organization and reducing manual inclusion of class files.
- PSR-7 standardizes HTTP message representation in PHP, facilitating interoperability between different frameworks and libraries that handle HTTP requests and responses.
- PSR-12 extends PSR-2, refining coding style guidelines for class and method declaration, property, and constant naming, among others, aiming for improved code readability and maintainability.
Step By Step Guide PHP Standard Recommendation (PSR)
Step 1: Create a folder and set up a PHP file using the .php extension

Step 2: Implement the code inside the PHP file without the code-sniffer extension
PSR.php
// Invalid way to write the Coding standards.
<?php
$a = 20;
$b = 10;
if($a > $b)
{
echo "a is greater than b";
}
Step 3: Install phpcs extension for vs code

Step 4:Further, Download the php_codesniffer by setting the composer section
Before using php_codesniffer, let's establish a Composer,
For Ubuntu use this ref:
After installing composer, Then, in your terminal, execute the following command:-
- composer require squizlabs/php_codesniffer
- cd ~/.config/composer/vendor/bin
- gedit ~/.profile
After Hitting gedit~/.profile command, instantly open your .profile page & you can additionally add the below lines in the last:
# Set PHPCS path in profile
export PATH=~/.config/composer/vendor/bin:$PATH
Step 5:Go to VS Code setting->Search (phpcs)->Enter the executable path manually for phpcs according to your project directory

Let’s Wrap It Up!
Now you can check your file, show errors of Coding Standards
And, here you will even get to know where you are making mistakes & why the code is facing issues while getting executed. Through this, you will be able to rectify them to let the code work smoothly.
At LN Webworks, our group of experts in Drupal are always prepared to help you make it happen. Get in touch with us right now to schedule a free consultation.
Share This Post:
Author Information

LN Webworks
Your Drupal Solution PartnerLN Webworks have championed open-source technologies for nearly a decade, bringing advanced engineering capabilities and agile practices to some of the biggest names across media, entertainment, education, travel, hospitality, telecommunications and other industries.
Talk With Certified Experts Of LN Webworks!
Related Articles
May 1, 2024
How To Make Interactive Websites And Why Do You Need One?
April 30, 2024
Implementation Of Open Social Distribution On A Local Server In Drupal
April 26, 2024