D
D
Dreaded2018-05-31 12:34:11
PHP
Dreaded, 2018-05-31 12:34:11

How to format this code according to PSR standards?

I try to write code following the PSR standards. I'm using PHPstorm, and it has such a great feature as code auto-formatting using standards.
Actually there are two questions:
1. Alignment of assignment expressions in code blocks.
As I write (one space before the assignment sign, and one after):

$variable = ['var1', 'var2', 'var3', 'var4'];
$variableWithALongName = array();
$variableWithAVeryLongName = array();

How PHPstorm formats my code (in one block of code - all consecutive assignment expressions are aligned with an equal sign)
$variable                  = ['var1', 'var2', 'var3', 'var4'];
$variableWithALongName     = array();
$variableWithAVeryLongName = array();

Question: how is it correct and where is it written?
2. Line length. Quote from PSR-2
НЕДОПУСТИМО жёстко ограничивать длину строки;
мягкое ограничение ДОЛЖНО составлять 120 символов;
СЛЕДУЕТ стараться, чтобы длина строки составляла 80 символов или менее.

How I write code:
$array['variable']  = 'В этой строке кода меньше 120 символов, но скорее всего больше чем 80';

How PHPstorm code is formatted:
$array['variable']
    = 'В этой строке кода меньше 120 символов, но скорее всего больше чем 80';

And if this is also combined with the previous question, then generally HELL will turn out. So I think. But here's what PHPstorm thinks:
$array['variable']
                           = 'В этой строке кода меньше 120 символов, то скорее всего больше чем 80';
$variable                  = ['var1', 'var2', 'var3', 'var4'];
$variableWithALongName     = array();
$variableWithAVeryLongName = array();

So how do you make these moments right?
The fact is that I am a beginner, and now I want to get my first job. At the moment I am training on test tasks found on the Internet, and while doing one of these tasks, I discovered the following requirement: following the PSR standards. I would like to know exactly from the point of view of a potential employer, how will writing code in these examples be evaluated?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
OnYourLips, 2018-05-31
@Dreaded

Question: how is it correct and where is it written?
Both options do not violate.
But the first one is preferable, there will be no extra lines in git diffs.
The setting is called alignment, it should be turned off.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question