Automattic / Automattic/VIP-Coding-Standards

Sniff idea: Detect when constant is being used in constant()

オープン
#717 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
PHP
スター
261
フォーク
44
平均マージ
19分
マージ済み PR(30日)
1

説明

## Describe the solution you'd like

Not sure if VIPCS is the best way forward, but I think this would be a worthy sniff.

When using `constant()`, we should throw a warning if a string is not being inputted. Of course it is valid PHP to do something like:

```
constant( FOO_BAR );
```

But I think most likely, what the user wants to do is:

```
constant( 'FOO_BAR' );
```

## What code should be reported as a violation?

```
constant( FOO_BAR );
```

## What code should *not* be reported as a violation?

```
constant( 'FOO_BAR' );
constant( "FOO_BAR" );
constant( $foo_bar );
```

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

まず、既存の VIPCS-PHP_CodeSniffer の sniff 規約と、constant() の呼び出しがどのように表現されるかを確認します。constant(FOO_BAR) は報告され、引用符で囲まれた文字列と変数は報告されないことを確認し、関連する sniff テストスイートで動作を検証します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
php
領域
tooling
issue の種類
機能追加
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
42/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。