Skip to content

feat(phpstan): analyse Latte templates - #41

Merged
WerySkok merged 18 commits into
masterfrom
phpstan-latte
Oct 30, 2026
Merged

WerySkok merged 18 commits into
masterfrom
phpstan-latte

Conversation

@WerySkok

@WerySkok WerySkok commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

НАСТОЯЩИЙ МАТЕРИАЛ (ИСХОДНЫЙ КОД) СОЗДАН И (ИЛИ) ОТРЕДАКТИРОВАН ПРИ УЧАСТИИ ИИ-АГЕНТА И (ИЛИ) КАСАЕТСЯ ДЕЯТЕЛЬНОСТИ ТАКОГО ИИ-АГЕНТА

PR добавляет анализ Latte-шаблонов в PHPStan. PHPStan проверяет шаблоны презентеров, layout-шаблоны и error-страницы.

Зачем: CI теперь находит ошибки в шаблонах. Раньше такие ошибки обнаруживались только в рантайме, выливаясь в 500 Server Error. Примеры ошибок: неизвестная переменная, неверный параметр include, отсутствующий шаблон.

Для работы проверки был взят плагин efabrica-team/phpstan-latte и вайб-форкнут для поддержки Latte 3.1.

Из нюансов: шаблоны в темах пока не анализируются.

…ctors

Presenters that define their own constructor without calling parent left the
typed property uninitialized. Keep the runtime property untyped and document
the TemplateScope type in PHPDoc; static analysis still resolves it.
GiftsPresenter::onStartup() overrides OpenVKPresenter::onStartup() and only
calls parent::onStartup(), but the collected context for the override does
not include variables assigned by the parent method body. Union the
onStartup()/onBeforeRender() context of every ancestor as well, so
presenter-wide variables such as thisUser survive lifecycle overrides.
- Do not report latte.cannotResolve when an explicit engine render was
  already collected for the method.
- Report a missing explicit render as latte.notFound instead of silently
  skipping it.
- Do not append .latte to _template values; Router falls back to the
  default template when the exact path does not exist.
Add an explicit ->render() method with no default template, a
_template override, and a template using the lifecycle-provided
csrfToken. These paths are now checked by the examples PHPStan job.
Keep the master dependency versions and add only the phpstan-latte dev
package and its direct dependencies.
Document the default-template over-approximation, the actual Router action
casing, and the class-string contract of methodMayRenderNothing().
…enders

Declare SimplePresenter terminators for the examples config, add a
notFound()-only action, render the explicit fixture before onBeforeRender
without csrfToken, and stop Router after the direct render.
Move the Chandler\PHPStanLatte PSR-4 mapping from autoload-dev to autoload
so installed applications can reference the resolver services. Analyse the
tools directory and document the VCS repository, terminating methods and
the current _templatePath/theme limitation.

@veselcraft veselcraft left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

лгтм кроме одного момента

@WerySkok
WerySkok dismissed veselcraft’s stale review October 30, 2026 11:12

Согласился с ответом в телеграме

@WerySkok
WerySkok merged commit 8f6ccfb into master Oct 30, 2026
3 checks passed
@WerySkok
WerySkok deleted the phpstan-latte branch October 30, 2026 11:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants