phpstan-analysis
БесплатноБез исполняемых скриптовНе проверенInvoke BEFORE running PHPStan or fixing PHPStan errors. Covers error resolution strategy (refactoring > phpDoc > ignoring), common Nette error patterns…
от nette★ 47 звёзд на GitHubОб этом скилле
PHPStan Analysis
Running PHPStan
Never use --error-format=json - its output format can change between PHPStan versions and is not designed for stable machine consumption. For machine-readable output, use --error-format=raw.
Take the verdict from the exit code, never from grepping the output. A filter defines what you see, so anything it misses reads as success - and some findings (an unmatched ignoreErrors pattern, for one) are not tied to any file and carry no file prefix at all.
Target Levels
Target level for Nette libraries is 8. Levels higher than 8 are not worth pursuing - the additional strictness (e.g., non-empty-string, positive-int) catches very few real bugs relative to the annotation burden.
- Level 7: Union types checked
- Level 8: Null checks, strict types (our target)
nette/phpstan-rules
Installed by all Nette libraries. It works in both directions, and mixing them up is a real hazard:
- It narrows types and silences false positives — many PHPStan errors disappear without manual fixes. Don't fight those (list below).
- It also REPORTS errors of its own and turns on stricter reporting. Two rules of its own:
nette.abortException(anAbortExceptioncaught and not rethrown — the fix is to rethrow it in its owncatch, which is not guessable) andnette.strings.regexpPattern(an invalid regular expression). On top of thatextension.neonforces nine flags on, includingcheckMissingCallableSignature,reportMaybesInMethodSignaturesandreportAlwaysTrueInLastCondition— so some errors exist only because this extension is installed. Those are genuine findings; never silence them.
It also registers universalObjectCratesClasses for DefaultTemplate, Database\Row,
SessionSection, SimpleIdentity and Html, so the most common property.notFound in a Nette
app is already solved — don't add @property annotations for those.
Don't add asserts, casts, or @var for errors that fall into these categories:
- Nette helpers:
Strings::match(),Arrays::invoke(),Helpers::falseToNull(),Expect::array(),Htmlmagic methods (setXxx/getXxx/addXxx),Container::getComponent()and$this['name'], Form$form['name'] - Native PHP functions:
|false/|nullremoved where unrealistic (getcwd,json_encode,preg_*, intl/GD/DOM/etc.)- For
preg_*with theumodifier,falsecan genuinely occur on invalid UTF-8 input, yet it is stripped by design — a regex call site should not double as input validation. So a dead=== falsecheck afterpreg_*(identical.alwaysFalse) is not a bug in the extension: refactor to an explicit up-frontpreg_match('##u', $s)validation, the one form wherefalseis preserved.
- For
- After
Tester\Assert:notNull(),type(),true(), etc. narrow the type - Silenced false positives: arrow fns passed to
test()/Assert::exception(), runtime variadic-closure type validation, Form event-handler callbacks with narrow data parameter
Two features require config in phpstan.neon (NOT app's common.neon):
Database row mapping — narrows Explorer::table(), ActiveRow::related(), ::ref() to concrete row classes. Keys may contain a single * wildcard; a bare * is the catch-all and substitutes PascalCase of the table name into * in the value. Exact keys win over wildcards; wildcards are tried in declaration order.
parameters:
nette:
database:
mapping:
tables:
booking: App\Entity\BookingRow # exact match
event_*: App\Entity\Event*Row # event_video → EventVideoRow
*: App\Entity\*Row # catch-all fallback
Asset type narrowing — narrows Registry::getMapper() / getAsset() / tryGetAsset() (and FilesystemMapper::getAsset() / ViteMapper::getAsset()) based on mapper ID and file extension. Values file and vite are shortcuts for the built-in FilesystemMapper / ViteMapper; any other value is treated as an FQCN of a custom mapper class.
parameters:
nette:
assets:
mapping:
default: file # FilesystemMapper
images: file
vite: vite # ViteMapper
custom: App\MyMapper # custom mapper FQCN
Full reference: Nette PHPStan Rules, bundled with the plugin.
Error Resolution Strategy
Resolution Priority
Resolve every error in this order of preference. Only fall back to the next step when the current one genuinely doesn't apply — this ladder is the backbone of the whole skill:
- Refactoring - if an error reveals a design weakness, fix the design first
- phpDoc - if the code is correct but its types are imprecise
assert()- sparingly, only when the type cannot be expressed otherwise- Ignore in
phpstan.neon- for systematic or intentional patterns, always with a comment explaining why - Baseline - last resort, keep minimal
Two hard
Установить phpstan-analysis в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл phpstan-analysis?
Invoke BEFORE running PHPStan or fixing PHPStan errors. Covers error resolution strategy (refactoring > phpDoc > ignoring), common Nette error patterns, baseline management, and type tests. Use this whenever the user mentions PHPStan, static analysis, type errors, wants to suppress warnings, or manage the baseline - even for a single error.
Как установить скилл phpstan-analysis?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл phpstan-analysis запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
skill-creator
Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an…
от Anthropicdiscernment-nudge
After you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals…
от Anthropicdata-consolidate
Joins the plant's scheduled exports and connector data into one working dataset — ERP items (NetSuite or Infor M3), sales orders, production work orders…
от Anthropicinspection-to-capa
Runs the quality chain end to end: writes the nonconformance against the requirement it violates, searches history at the moment of writing to say whether…
от Anthropic