Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PhpStorm and PSR-12, how can I add it as default coding style?

Tags:

php

phpstorm

PSR-12 is an extension of PSR-2, and therefore also an extension of PSR-1. The basis of PSR-12 is PSR-2 and therefore a list of differences is provided below to assist with migration but it should be considered as an independent specification.

From the php-fig site. Long story short, while not mandatory, it covers more code cases than PSR-2.

I'd like to use it in PhpStorm. Unfortunately, by default, storm doesn't offer this option. At predefined styles you have a fairly comprehensive list, but not comprehensive enough.

enter image description here

Of course, I can always define the style myself doing it by hand, but that doesn't strike me as a good idea. Mostly because I WILL miss something and if there are any updates to the PSR I can't easily update it. Not to mention I can't share it properly with my team. Except maybe exporting my .idea folder.

I googled around for a plugin or something of that sort but came up empty handed.

like image 687
Andrei Avatar asked Aug 13 '19 10:08

Andrei


People also ask

How can I get beautify code in PhpStorm?

In the editor, select a code fragment you want to reformat. Before reformatting, you can take a look at the code style settings that are applied to the selected code: press Alt+Enter and click Adjust code style settings. From the main menu, select Code | Reformat Code or press Ctrl+Alt+L .

What PSR 12?

PSR-12 seeks to provide a set way that both coding style tools can implement, projects can declare adherence to and developers can easily relate on between different projects for these coding style reducing cognitive friction.

Can PhpStorm run PHP?

To be able to run an application from PhpStorm, you first need to configure a PHP interpreter as described in Configure local PHP interpreters and Configure remote PHP interpreters. After that, you can do any of the following: Run a single script from the code editor. Create and run a dedicated run/debug configuration.

How do I import a WebStorm code style?

Manage a code style scheme From the list, select one of the following options: Rename: change the name of the selected scheme. Export: export your code style settings to the desired location. Import: import WebStorm XML code style settings, JSCS config file, or Eclipse XML Profile.


2 Answers

You cannot add custom entry there as a user unless you write a plugin that will do that.

WI-48160 / WI-45330 -- watch these tickets (star/vote/comment) to get notified on any progress.

The implementation of these tickets will bring a new entry in that list.


UPDATE 2019-10-08: PSR-12 Code Style preset has been added for 2019.3 version (currently in EAP stage).

like image 126
LazyOne Avatar answered Oct 22 '22 15:10

LazyOne


You can now add it from the dropdown, must've changed some time in the past 2 years. enter image description here

like image 40
Sarel Avatar answered Oct 22 '22 13:10

Sarel