PSR 40.000 — PHP的银河编码标准

dev-main 2024-02-18 10:31 UTC

This package is auto-updated.

Last update: 2024-09-18 11:38:19 UTC


README

PHP License: MIT

「很久以前,在一个遥远的星系中……」

编程标准已经变得如此详细,以至于它们开始触及命名和代码组合的几乎所有细节。其中之一就是PSR 40.000,帝国的最后堡垒,描述了军队FOBAR标准的接口。毕竟,即使是示例中描述的任意对象也必须有法定规范。

以下情况下指示使用这些标准

🚫 错误

<?php

class Foo
{
   // ... //
}

class Bar
{
   // ... //
}

class Baz
{
   // ... //
}

🎖️ 正确

<?php

use Fomiash\Psr40000\{FooInterface, BarInterface, BazInterface};

class Foo implements FooInterface
{
   // ... //
}

class Bar implements BarInterface
{
   // ... //
}

class Baz implements BazInterface
{
   // ... //
}

🚫 错误

<?php

class Bar
{
   // ... //
}

class Foo
{
   // ... //
}

class Baz
{
   public function __construct(public Bar $bar, public Foo $foo) {}
}

🎖️ 正确

<?php

use Fomiash\Psr40000\{FooInterface, BarInterface, BazInterface};

class Foo implements FooInterface
{
   public function __construct(
    public BarInterface $bar,
    public BazInterface $baz) {}
}

class Bar implements BarInterface
{
   // ... //
}

class Baz implements BazInterface
{
   // ... //
}

使用Guards Composer进行安装

composer require fomiash/psr40000