Questions tagged [psr-2]

PSR-2 is a PHP Standards Recommendation containing PHP's Coding Style Guide.

PSR-2 is a PHP Standards Recommendation containing 's Coding Style Guide. It extends and expands .

67 questions
1
vote
1 answer

PHP PSR 2 coding style space after function name

The PHP PSR 2 coding style guide requires there to NOT be any space between a function name and the opening bracket following it. This applies when writing the function signature: Method names MUST NOT be declared with a space after the method…
alamoot
  • 1,966
  • 7
  • 30
  • 50
1
vote
1 answer

PHP code style alignment for '=' and '->'

To align or not to align... Pros and cons of the following approaches. I like to use first case. Because I think it's optimal, but someone else thinks otherwise. when adding a new constant to the file - diff is 1 string, not more clearer, more…
Ivan
  • 625
  • 1
  • 5
  • 18
1
vote
1 answer

SonarQube: Message displayed in PHP code

I have this statement: return ++$maxContratNum; SonarQube display this message: Extract this increment or decrement operator into a dedicated statement what's meaning this message ?? Thank you
fatma_wings
  • 113
  • 1
  • 15
1
vote
1 answer

Is there any PSR / convention about Alternative Syntax?

I've seen a lot of posts talking about why alternative Syntax in PHP is good/bad. It's not the topic, I'm a convention lover and I want to know if there's about convention about it. Have a clean code is one of my priority. I'm pretty sure it's not a…
1
vote
1 answer

PSR doc comments

Is there a documentation about the psr standards for doc comments in php. example: /** @var string $str */ $str = "test"; /** @var array $arr */ $arr = []; is this allowed or do I need to do it like this: /** @var string $str */ $str = "test"; /**…
nusje2000
  • 493
  • 9
  • 25
1
vote
0 answers

Rule CloseBraceAfterBody of PSR2 can not be autofixed from PhpStorm

In my projects I apply the PSR-2 code styling rules and I use Codesniffer to check my code through Continues Integration. I use PhpStrorm to write my code and PhpStorm has a functionality to reformat the code before commiting or while writing your…
gmponos
  • 2,157
  • 4
  • 22
  • 33
1
vote
1 answer

Issue while validating with PSR-2 on Prestashop Validator

While validating my new module on Prestashop Validator, I am getting the following error in my main controller file (php file). End of line character is invalid; expected "\n" but found "\r\n" I am getting the error on the first line that only has…
Wolfack
  • 2,667
  • 1
  • 26
  • 50
1
vote
0 answers

PSR for nested IF condition

I am just to migrate my code in to PSR standard. I am not sure about how to write it inside nested condition. I am confused by line spacing. Can I use one line space after If condition ? Below is my example code. if ($this->value) { if…
shivanshu patel
  • 782
  • 10
  • 19
0
votes
1 answer

Code style for separating lines with > 120 symbols. Where should write equal symbol?

I interesting your opinion about code style for separating lines with > 120 symbols. Where should write equal symbol? On the first line or next line? Example #1 const MY_LONG_LONG_ORIGINAL_CONST_NAME_EXAMPLE = …
maybe_vp
  • 1
  • 1
0
votes
0 answers

Will a carriage return be correct or not for the PSR-2?

I use to create my classes like this, with an extra blank line after the closing } (here line 9):
0
votes
1 answer

PHP long ternary operator line and 120 char line long PSR rule

Is there a good way to format long ternary operator line ? Let's say : $order = new Order($this->isProfessionalChildCollaborator($this->getUser()) ? $this->getUser()->getParent() : $this->getUser()); This is too long according to 120 char per line…
nbonniot
  • 1,034
  • 16
  • 33
0
votes
0 answers

Custom coding standard ruleset not working for Code Sniffer in PhpStorm

I have a project in PhpStorm 2019.2.3 for which I want to use a custom coding standard ruleset with PHP Code Sniffer. The Code Sniffer works as expected, when I choose a provided coding standard, but when I change to my custom ruleset, all sniffs…
jasie
  • 2,192
  • 10
  • 39
  • 54
0
votes
1 answer

Is a good practice aliasing php native functions?

would help PSR naming conventions. Would it be a good practice? Example: use function array_keys as getArrayKeys;
apedic
  • 139
  • 2
  • 9
0
votes
0 answers

PSR-2 VS Codeigniter Framework Style guidelines

There are contradictions between PSR-2 and Codeigniter Style Guidelines: Allman style indenting in CI which is discouraged in PSR-2 elseifs on new line in allman private methods in classes prefixed with underscore in CI and NOT in PSR-2. TRUE,…
0
votes
2 answers

Symfony 3.3 - where should I put CSS and JS files?

THIS link suggests that /app directory contains all configuration, templates (.html.twig files) and translations, and the /src directory contains PHP code. However, HERE we can see that .css and .js files are loaded from…