Everything you Need to Know About PSR
PSR also known as PHP Standard Recommendation, it is a PHP specification that is used in many standardize programs. Mainly it is used to enable component interoperability and provide a basic technical basis for implementing concepts to improve programming. It is established by the PHP Framework Interop Group. The PSR standards use for example to be able to develop different components for Laravel that work effectively with other frameworks like Symfony.
Here are the main 4 types of PSR as per the Best Web Design Company in India,
=>PSR-1: Basic Coding Standard
=>PSR-6: Caching Interface
=>PSR-12: Extended Coding Style Guide
=>PSR-0: Autoloading Standard
=>PSR-2: Coding Style Guide
=>PSR-5: PHPDoc Standard
=>PSR-19: PHPDoc tags
=>PSR-9: Security Advisories
=>PSR-10: Security Reporting Process
Here are some detail information about main PSR’s
PSR-1: Basic Coding standard
Here it includes what should be considered the standard coding parts required to ensure a high level of technical interoperability between shared PHP code.
=>PHP code MUST use only <?php and <?= tags.
=>PHP code MUST use only UTF-8 without BOM.
=>Class names MUST be listed in StudlyCaps.
=>Class constants MUST be reported in all uppercase with underscore separators.
=>Method names MUST be listed in camelCase.
PSR-6: Caching Interface
Caching is a way you can improve the overall performance of the project, making caching libraries is a common feature of many frameworks and libraries.
Here are the main two key concepts,
It represents a collection of items in a caching system. The pool is a valid container of all the items it contains. All cacheable items retrieved from the pool as an item object and all communication of cached objects passes through the pool.
The item represents a single or value pair within a Pool. The key is the initial unique identifier for an Item. Also, its value may be changed at any time.
PSR-12: Extended Coding Style Guide
This PSR provides a set that coding style tools can implement, projects can declare adherence to and developers can relate with different projects. When multiple authors collaborate across multiple projects it becomes very helpful to have a set of guidelines to use among all those projects.
==>There must not be a harsh limit on line length.
==>Lines should not be longer than 80 characters
==>There must not be tracing whitespace at the end of the lines.
==>Make sure there must be only one statement per line.
PSR-0: Autoloading Standard
It shows all the required requirements that must be met for the autoloading, by setting up namespaces corresponding to hard disk file trees.
==>All namespace must have a top-level namespace
==>Each namespace can have as many subspaces of names as required and is optional.
==>Each _ character in the class name is reformed to DIRECTORY_SEPARATOR.
==>The full namespace and class are suffixed with.php
==>Alphabetic characters in vendor names, namespaces, and class names may be of any sequence of lower case and upper case.
PSR-2: Coding Style Guide
This PSR extends and expands the PSR -1.
The code must follow a “coding style guide” PSR
==>The code must use 4 spaces for indenting, not tabs.
==>There must have a soft limit of 120 characters and lines should be 80 characters not more than that.
==>Opening blocks for classes and methods must go on the next line, and closing blocks must go on the next line after the body.
==>When it comes to Control Structure all the keywords must have one space after them.
PSR-5: PHPDoc Standard
The main goal of the PSR-5 PHPDoc Standard is to provide a complete definition of the PHPDoc standard.
To learn more about the PSR and the importance of correct PSR for your business you can visit one of the Best Web Design Company in India Windzoon Technologies. They have a team of dedicated web developers, they know all the tactics of web development. To solve your any doubts or to discuss your project with us, call us on,+91 9904713335 or connect with our expert in LinkedIn