1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

code_sniffer で「namespace 宣言のあとに 1 つの空行を記述してください。」

Posted at

Question

Sider(旧SideCI)の CodeSniffer で空行を入れているのにグローバル名前空間の場合エラーが発生する

[code_sniffer] namespace 宣言のあとに 1 つの空行を記述してください。
There must be one blank line after the namespace declaration

エラーが起きるパターン1
<?php
// 汎用のため明示的にグローバル名前空間に設置
namespace {

/* [Main] ============================================================== */

// コード
エラーが起きるパターン2
<?php
namespace { // 汎用のため明示的にグローバル名前空間に設置

/* [Main] ============================================================== */

// コード

Answer

名前空間を明示的にグローバル名前空間にする場合、namespace の後には2行入れないとパスしないらしい。何気にハマってしまった。ちょっと気持ち悪い。

OKパターン1
<?php
// 汎用のため明示的にグローバル名前空間に設置
namespace {


/* [Main] ============================================================== */

// コード
OKパターン2
<?php
namespace { // 汎用のため明示的にグローバル名前空間に設置


/* [Main] ============================================================== */

// コード

SideCI.yml の設定

sideci.yml
linter:
  code_sniffer:
    version: 3
    dir: ./
    options:
      extensions: php,inc
      standard: PSR2
      encoding: utf-8
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?