Эта спецификация расширяет и заменяет PSR-12 и требует соблюдения базового стандарта кодирования PSR-1.
Кстати, на днях, вышла новая версия код стайла для PHP, в которой были исправлены проблемы предыдущей версии, а так же были обновлены правила для нового синтаксиса PHP, такие, как например:
- добавлен раздел с описанием nowdoc и heredoc
function notAllowed()
{
$notAllowed = <<<'COUNTEREXAMPLE'
This
is
not
allowed.
COUNTEREXAMPLE
}
//
function allowed()
{
$allowedHeredoc = <<<COMPLIANT
This
is
a
compliant
heredoc
COMPLIANT;
$allowedNowdoc = <<<'COMPLIANT'
This
is
a
compliant
nowdoc
COMPLIANT;
var_dump(
'foo',
<<<'COMPLIANT'
This
is
a
compliant
parameter
COMPLIANT,
'bar',
);
- добавлен раздел о коротких замыканиях
$func = fn(int $x, int $y): int => $x + $y;
$func = fn(int $x, int $y): int
=> $x + $y;
$func = fn(
int $x,
int $y,
): int
=> $x + $y;
$result = $collection->reduce(fn(int $x, int $y): int => $x + $y, 0);
- добавлены правила о конечных запятых
function beep(string $a, string $b, string $c)
{
// ...
}
function beep(
string $a,
string $b,
string $c,
) {
// ...
}
$arr = ['a' => 'A', 'b' => 'B', 'c' => 'C'];
$arr = [
'a' => 'A',
'b' => 'B',
'c' => 'C',
];
$result = match ($a) {
'foo' => 'Foo',
'bar' => 'Bar',
default => 'Baz',
};
- обновлен раздел ключевых слова-модификаторов abstract/final
<?php
namespace Vendor\Package;
abstract class ClassName
{
protected static readonly string $foo;
final protected int $beep;
abstract protected function zim();
final public static function bar()
{
// method body
}
}
readonly class ValueObject
{
// ...
}
- перефразировали «MUST… no» на «MUST NOT… any»
- добавлен раздел о перечислениях
enum Suit: string
{
case Hearts = 'H';
case Diamonds = 'D';
case Spades = 'S';
case Clubs = 'C';
const Wild = self::Spades;
}
- добавлена спецификация стиля цепочки методов
- добавлено руководство по стилю атрибутов
#[Foo]
#[Bar('baz')]
class Demo
{
#[Beep]
private Foo $foo;
public function __construct(
#[Load(context: 'foo', bar: true)]
private readonly FooService $fooService,
#[LoadProxy(context: 'bar')]
private readonly BarService $barService,
) {}
/**
* Sets the foo.
*/
#[Poink('narf'), Narf('poink')]
public function setFoo(#[Beep] Foo $new): void
{
// ...
}
#[Complex(
prop: 'val',
other: 5,
)]
#[Other, Stuff]
#[Here]
public function complicated(
string $a,
#[Decl]
string $b,
#[Complex(
prop: 'val',
other: 5,
)]
string $c,
int $d,
): string {
// ...
}
}
- описание именованных аргументов
somefunction($a, b: $b, c: 'c');
- уточнение правил пустых операторов
Почитать можно на https://github.com/php-fig/per-coding-style/blob/master/spec.md
Что думаешь?