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
2
votes
0 answers

Resolve a PHPCS error in a Laravel migration file

In all my laravel migrations I want to use PSR2, but I getting a warning. use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; class CreatePlayersTable extends Migration { // migration } The…
LeBlaireau
  • 17,133
  • 33
  • 112
  • 192
2
votes
3 answers

How to implement a copy constructor in PHP?

I have a class Account which has a default constructor function: class Account { AccountType $type; AccountLabel[] $labels; AccountAttribute[] $attributes; // Initializes a new account and assigns labels to the new account. …
Believe2014
  • 3,894
  • 2
  • 26
  • 46
2
votes
1 answer

PSR-2 - Should the array opening bracket be on its own line

If we are conforming to PSR-2 standards, going off their description for multi-line arguments: Argument lists MAY be split across multiple lines, where each subsequent line is indented once. When doing so, the first item in the list MUST be on…
Mikey
  • 2,606
  • 1
  • 12
  • 20
2
votes
1 answer

PSR for using description of class

I can't find anything saying in PSR about where should placed comment about class and namespace. Is it should be first description of class or namespace?
Timur
  • 488
  • 4
  • 14
2
votes
1 answer

phpcs Is there a rule to disallow empty lines?

Is there a rule that I can use with phpcs that limits the number of consecutive empty lines to e.g. 3? I currently use PSR2, which does not take this into consideration at all.
Chris
  • 13,100
  • 23
  • 79
  • 162
2
votes
2 answers

PHP-CS-FIXER is ignoring my config

I have created a file called .gm_cs in the root of my project and php-cs-fixer is installed globally. In the config file is the following true, 'combine_consecutive_unsets' => true, …
jsnfwlr
  • 3,638
  • 2
  • 23
  • 25
2
votes
1 answer

Verify if my yii 1.1.x project is PSR-2

If yii 1.1.x support PSR-2 ? I mean original framework? If there is some tool to verify if my yii 1.1.x project(or just php project) corresponds to PSR-2 ?I am tring to write in PSR-2, but old habits are difficult to overcome...
user2054381
2
votes
1 answer

PSR Standard One statement per line

Is this 2 statements or 1? if ($a == "A" && $b == "B") { // do something } How do I use two statements if I want to follow PSR standards? Should I use multiple if's? Like if inside an if?
1
vote
2 answers

Is it necessary to put space after $this keyword in OOP PHP according to PSRs?

I studied PSR-2 and PSR-12 documentations completely but didn't find any explanation regarding whether to put any space after $this keyword. My exact question is which one of following styles is more correct according to PSRs: return…
IT_man2018
  • 53
  • 7
1
vote
1 answer

How many new lines before namespace declaration in PSR?

PSR has a fairly clear stance regarding new lines after namespace declaration: When present, there MUST be one blank line after the namespace declaration. But what about blank lines before namespaces? Are there any rules or limitations about it? I…
Gino Pane
  • 4,740
  • 5
  • 31
  • 46
1
vote
1 answer

Can I use the if-statement in single row according to the PSR-2?

I need to know if I'am allowed to use single row if-statements according to the PSR-2 Coding Style. I've already read the docs but i couldn't find any information about…
1
vote
1 answer

PhpStorm: Auto-format with line breaker

I'm working on a new project with existing sources. And the guy who's writte code used a weird format code. See bellow : public function analyzeCalcul ( $calcul , $selection …
Kiloumap Mrz
  • 2,133
  • 1
  • 9
  • 18
1
vote
1 answer

Uppercase Booleans in Netbeans 8.2

When I using netbeans 8.2 for PHP code, it always give NULL FALSE TRUE in uppercase. But PSR-2 tells us The PHP constants true, false, and null MUST be in lower case. How I can change it, and netbeabs give it in lowercase
Los Vitaly
  • 21
  • 3
1
vote
1 answer

Private member variable must be prefixed with an underscore

In PhpStorm, I am adding some code to a class. The class has a private property defined via this line: private $pdfService ... but the line is underlined by the IDE's syntax checker. Hovering over the line shows the following error message:…
1
vote
0 answers

String Concatenation Convention

What is the best practice in concatenating multiple strings? What I did is every concatenation will be on the next line? I'm following the psr-2 80 line limit and the 120 line soft limit. e.g. return ( Config::get('url')['base_folder'] . …
Kevin Karl Leaño
  • 1,630
  • 3
  • 15
  • 20