Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

phpstan-analysis

БесплатноБез исполняемых скриптовНе проверен

Invoke BEFORE running PHPStan or fixing PHPStan errors. Covers error resolution strategy (refactoring > phpDoc > ignoring), common Nette error patterns…

netteот 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 (an AbortException caught and not rethrown — the fix is to rethrow it in its own catch, which is not guessable) and nette.strings.regexpPattern (an invalid regular expression). On top of that extension.neon forces nine flags on, including checkMissingCallableSignature, reportMaybesInMethodSignatures and reportAlwaysTrueInLastCondition — 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(), Html magic methods (setXxx/getXxx/addXxx), Container::getComponent() and $this['name'], Form $form['name']
  • Native PHP functions: |false / |null removed where unrealistic (getcwd, json_encode, preg_*, intl/GD/DOM/etc.)
    • For preg_* with the u modifier, false can 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 === false check after preg_* (identical.alwaysFalse) is not a bug in the extension: refactor to an explicit up-front preg_match('##u', $s) validation, the one form where false is preserved.
  • 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:

  1. Refactoring - if an error reveals a design weakness, fix the design first
  2. phpDoc - if the code is correct but its types are imprecise
  3. assert() - sparingly, only when the type cannot be expressed otherwise
  4. Ignore in phpstan.neon - for systematic or intentional patterns, always with a comment explaining why
  5. Baseline - last resort, keep minimal

Two hard

Полный SKILL.md на GitHub

Установить 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), без исполняемых скриптов.

Похожие скиллы

Сравнить phpstan-analysis с