简体   繁体   English

PSR:命名空间声明前有多少新行

[英]PSR: How many new lines before namespace declaration

Ok, so PSR stands clearly regarding new lines after namespace declaration好的,所以 PSR 明确表示命名空间声明后的新行

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 believe I've seen something somewhere, but cannot find now.我相信我在某处看到过一些东西,但现在找不到了。

The section 3. Declare Statements, Namespace, and Import Statements in PSR-12 talks about the various parts of the start of the script and states3. PSR-12 中的声明语句、命名空间和导入语句部分讨论了脚本开始和状态的各个部分

The header of a PHP file may consist of a number of different blocks. PHP 文件的标题可能由许多不同的块组成。 If present, each of the blocks below MUST be separated by a single blank line , and MUST NOT contain a blank line.如果存在,下面的每个块必须由单个空行分隔,并且不得包含空行。 Each block MUST be in the order listed below, although blocks that are not relevant may be omitted.每个块必须按下面列出的顺序排列,尽管可以省略不相关的块。

(emphasis mine). (强调我的)。

Also following is the example另外下面是例子

<?php

/**
 * This file contains an example of coding styles.
 */

declare(strict_types=1);

namespace Vendor\Package;

use Vendor\Package\{ClassA as A, ClassB, ClassC as C};

which shows the spacing.这显示了间距。

The main thing I read from this is not about defining the number of blank lines before but more defining that any of the components must have a single blank line between them.我从中读到的主要内容不是之前定义空行的数量,而是更多地定义任何组件之间必须有一个空行。

Just a comment about PSR-2 , is does state只是关于PSR-2的评论,是没有状态

Deprecated - As of 2019-08-10 PSR-2 has been marked as deprecated.已弃用- 截至 2019 年 8 月 10 日,PSR-2 已被标记为已弃用。 PSR-12 is now recommended as an alternative.现在推荐 PSR-12 作为替代方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM