Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

AlwaysReturnInFilter: isInsideIfConditonal() guards the conditions array after reading it

クローズ 初心者向け
#903 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

関連するプルリクエストがすでにマージされています。

  • #905 @tomjn による — マージ済み

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
78/100
issue の種類
リファクタリング
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
php
領域
tooling

調査の方向性

AlwaysReturnInFilterSniff::isInsideIfConditonal() から始めて、トークンの conditions 配列がどのように読み取られているかを調べます。説明されているとおりに guard と reset のロジックを簡素化し、その後も sniff が同じケースを報告することを確認します。整理によって報告動作が維持されれば完了です。

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

説明

This is a tidy-up. It does not change what the sniff reports.

AlwaysReturnInFilterSniff::isInsideIfConditonal() decides whether a return in a filter callback sits inside an if. It has a guard for a token that has no conditions array, but the guard comes after two end() calls that have already read that array, so it protects nothing. PHP_CodeSniffer sets conditions on every token, so the guard is not needed in the first place.

The reset() call between the two has no effect on the result either. It only undoes the array pointer move that end() made on the shared token array.

The method can read the array once, return false when the innermost condition is a function or closure, and otherwise return in_array( T_IF, $conditions, true ).

@GaryJones spotted this while reviewing #901. It was left out of that PR because that one only adds return types.

主要言語
PHP
スター
261
フォーク
44
平均マージ
3日 17時間
マージ済み PR(30日)
9

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

Automattic/VIP-Coding-Standards のほかの issue

Automattic/VIP-Coding-Standards の issue をすべて見る

似ている issue

PHP の issue をもっと見る

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

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