入門編の増補と、本文とPHPファイルの整合性チェック - #2
Merged
Merged
Conversation
- ```php file=N.php``` blocks must match the file contents - ```php phpstan``` blocks are analysed standalone - // DumpedType: / // Error: annotations are verified against real PHPStan output - answers/ are analysed one by one and must be error-free - composer check runs everything; GitHub Actions runs it on push/PR
Placed outside phpstan.dist.neon paths because they redeclare the same symbols as the exercise files and would collide in a whole-project run.
- 1: constant types, integer range types (int<0, max>), tracking vs widening - 2: how to read PHPStan error messages, mixed, levels, error identifiers - 3: show Author/Book, comparison-operator and is_*() narrowing, !$word caveat - link answer files from each exercise - tag code blocks with file=/phpstan and DumpedType/Error annotations
- Move the constant/integer-range examples out of 1.php into a new section 1.5 with its own file, so section 1 stays focused - Add `use function PHPStan\dumpType;` / `assertType;` to every script and answer; explain that dumpType() may be written unqualified while the text keeps \PHPStan\dumpType() for consistency - Playground links now need regeneration (TODO comments per section)
The Playground's Share button POSTs to https://api.phpstan.org/analyse with saveResult: true and gets back an id for https://phpstan.org/r/<id>. - check: fetch each linked sample (GET /sample?id=) and compare its code and config with the local file (read-only; runs in CI) - update: publish stale/missing samples, rewrite the README link and drop the <!-- TODO --> marker (--dry-run to preview) - config mirrors phpstan.dist.neon: level 10, bleedingEdge on, strictRules off
- Read the HTTP status from stream_get_meta_data() instead of the $http_response_header variable, which is deprecated in PHP 8.5 - Iterate the live lines array by index; foreach iterated a copy, so after removing a TODO line the indices no longer matched and the **File** line was not found for the following sections - Publish new samples for all sections (1, 1.5, 2, 3, 4, basic 1) and drop the TODO markers
zonuexe
force-pushed
the
update/beginner-2
branch
from
August 19, 2026 00:28
c3adbfb to
1fb39dc
Compare
zonuexe
marked this pull request as ready for review
August 19, 2026 06:38
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
入門編 (beginner) を増補し、あわせて Markdown 本文と PHP ファイル・PHPStan の実際の出力が矛盾しないようにする仕組みを追加しました。
入門編の増補
beginner/1.5.php) として追加。定数型 (5,6) と整数範囲型 (int<0, max>,positive-int) をdumpType()で体感するuse function PHPStan\dumpType;/assertType;を追加。§1 の TIP で「dumpType()とも書けるが、本文は\PHPStan\dumpType()で統一する」と明記mixedの意味、レベル (Playground の Level 10)、エラー識別子を紹介Author/Bookクラスの掲載と TIP (コンストラクタプロモーション /readonly class/non-empty-array)、「ほかの絞り込み方」小節 (比較演算子 →int<1, 100>、is_string()→mixedからstring)、!$wordがnon-falsy-stringになる注意整合性チェックの仕組み (
composer check)tools/check-docs.phpが README のコードブロックを検査します。詳細はCONTRIBUTING.md。```php file=3.php— ブロックが演習ファイルの連続する行と一致すること (タブ/スペース差は無視、// ...で省略可)```php phpstan— ブロック単体を PHPStan で解析// DumpedType: X/// Error: message注釈 (行末または直前行) が実際の出力と過不足なく一致することanswers/**/*.phpが単体でエラーなしであること.github/workflows/check.ymlで PR/push 時に実行します。解答例
answers/answers/beginner/2.phpのように配置しました。演習ファイルと同じディレクトリに置くとphpstan analyseの一括実行でlabel()やBookの定義が衝突して誤検出が出るため (excludePathsで除くと今度は明示指定でも解析されない)、paths外に置いています。Playground リンクの検査・更新 (
tools/playground.php)Playground の Share ボタンと同じ API (
POST https://api.phpstan.org/analyse+saveResult: true) を叩き、GET /sample?id=で保存内容を照合します。composer check-playground— リンク先サンプルのコード・設定がローカルの演習ファイルと一致するか (読み取りのみ、CI で実行)composer update-playground— 不一致/TODO のリンクを新規発行して README を書き換え (--dry-runあり)全節のリンクを再生成済みです (Level 10, bleedingEdge オン, strictRules オフ = ローカル設定と同じ)。
TODO (Draft の理由)
動作確認