ExpressionEngine Adopts PSR-12
3/16/2020 / By Andy McCormick
3/16/2020 / By Andy McCormick
From this point forward, the ExpressionEngine team and anybody contributing to the ExpressionEngine open source project will be expected to conform to PSR-12
What is PSR and PSR-12
More than just an argument starter at a bar full of developers, PHP Standard Recommendation, better known as PSR, is a set of guidelines and concepts meant to bring uniformity to how developers write and interpret PHP code. A quick Google search on code styles will show the many benefits of having clean well written code within a company or a project. However, PSR takes that a step further and gives us guidelines and principles that can be followed by the entire PHP community. This allows developers to easily contribute to multiple projects without being burdened by having to learn multiple code style guides as well as makes it easy for individual teams to quickly implement a set of code standards which have been thoroughly discussed and vetted by leaders in the PHP community. For more on PSR and the group behind the standards checkout the PHP-FIG website
PSR-12 is a particular recommendation dealing with code styling. Per the PHP-FIG website: “Like PSR-2, the intent of this specification is to reduce cognitive friction when scanning code from different authors. It does so by enumerating a shared set of rules and expectations about how to format PHP code.” Essentially it gives PHP developers a shared set of styling guidelines to follow.
Why does PSR-12 Matter
As an open source project, we look to the community to contribute and help grow the ExpressionEngine platform. While it’s easy to say that a project is open source, it’s much more difficult to both manage and contribute to the project without clear guidelines as to how the project is to be developed. PSR-12 helps with part of this. When we say that any code written for ExpressionEngine is to be written according to PSR-12 standards, all developers contributing to the project know what their code should look like. This helps to maintain a seamless core of code rather than a pile of spaghetti.
As an open source project, we look to the community to contribute and help grow the ExpressionEngine platform
An accepted standard like PSR-12 also allows developers to focus on the logic of their code and what the purpose of their code is instead of worrying about tabs or spaces. Libraries like PHP Code Sniffer (PHPCS) and PHP Code Beautifier and Fixer (PHPBF) can be implemented with your favorite code editors and IDE’s to easily format your code according to standards. This wouldn’t be possible without using a community accepted standard.
PSR-12 also makes it easier for developers in the community to not only contribute code, but also contribute to reviewing code. When code is all written the same way, developers can easily read and understand the code without having to spend a ton of brian power trying to figure out what the code is even doing (that’s the reduction of “cognitive friction” that the standard refers to).
ExpressionEngine and PSR-12
From this point forward, the ExpressionEngine team and anybody contributing to the ExpressionEngine open source project will be expected to conform to the PSR-12 standard. We will not be refactoring all of ExpressionEngine 5.3.x code or earlier to match PSR, nor necessarily refactoring all of what has been written for ExpressionEngine CMS 6. However as we continue to build and work on new versions and updates to previous versions, the code will conform to the PSR-12 standard. Even as we refactor older files we work on and update the formatting for PSR-12, we will not be refactoring any function or method names as this would lead to major breaking changes.
We know the community is looking forward to this change as we work together to build an amazing product. If you have any questions about this or would like to discuss with the community, be sure to join the conversation over in Slack.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.