根据PSR2,在多维数组的键和值之间有空格的正确方法是什么.
$result = [
'key1' => 'value1',
'another_key' => 'value2',
'some_other_key' => 'value3'
];
VS
$result = [
'key1' => 'value1',
'another_key' => 'value2',
'some_other_key' => 'value3'
];
它看起来第一个更具可读性,但我们有额外的空间.
解决方法:
根据:-PSR-2 multiline array indentation missing
PSR-2 doesn’t define how arrays should be indented, or if they should
even be indented at all, so PHPCS can’t enforce any rules in this
area.When I have asked about arrays in other areas of the standard, the
response was to treat them like a single object, and ignore them. So
many PHPCS checks for PSR-2 actually skip right over arrays and don’t
do any checking inside them either.So this isn’t a bug, and it’s also not something I can add to PHPCS
because PSR-2 doesn’t define an array formatting standard.
注意:-
同样的事情也在这个帖子中说明: – Question on proper Array syntax
There’s no correct answer, beacuse the PSR is silent on the matter,
but I think your assumption is reasonable. It’s certainly my practice.
即使你检查这个帖子: – Coding Style Guide Additions
它只说明了添加,而不是关于添加空格的任何内容.
Arrays that span across multiple lines can have a trailing comma to
make sure that adding new rows does not change the previous row, as
well.
标签:php,psr-2 来源: https://codeday.me/bug/20190701/1348540.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。