Skip to content

CC-39568 Enforce typed class constants and forbid redundant docblocks - #36

Merged
stereomon merged 4 commits into
feature/cc-39568-suite-architecture-rulesfrom
feature/cc-39568-enforce-typed-consts-no-redundant-docblocks
Jul 20, 2026
Merged

CC-39568 Enforce typed class constants and forbid redundant docblocks#36
stereomon merged 4 commits into
feature/cc-39568-suite-architecture-rulesfrom
feature/cc-39568-enforce-typed-consts-no-redundant-docblocks

Conversation

@stereomon

Copy link
Copy Markdown
Contributor

Adds tooling so this package can never carry untyped class constants or redundant type-restating docblocks.

What it enforces

  • Native-typed class constants (PHP 8.3+) via a new PHPStan self-check rule; missing native type is an error.
  • Redundant @param/@return/@var docblocks that only restate a native type are forbidden via phpcs (raw Slevomat type-hint sniffs); array-shape and narrowing docblocks (list<...>, array<...>, class-string<...>) remain exempt.
  • Spryker's mandatory-@return/@return void DocBlock sniffs are surgically lifted where they collide with the above; the rest of the Spryker docblock checks stay in force.

The constant rule is self-enforcement only (wired in the test phpstan config, not extension.neon), so it checks this package's own src/ and is not imposed on consuming Spryker projects. It can be promoted to extension.neon later if we want it exported to consumers.

Test plan

  • vendor/bin/phpcbf then vendor/bin/phpcs -p src/ tests/ — clean.
  • composer test — all pass (incl. the new rule's RuleTestCase with Good/Bad fixtures).
  • composer stan — no errors; verified a temporary untyped constant is flagged, then removed.

phpcs: reference the raw Slevomat ParameterTypeHint/ReturnTypeHint/
PropertyTypeHint sniffs to forbid @param/@return/@var annotations that only
restate a native type (array-shape and narrowing docblocks stay exempt), and
surgically lift Spryker's mandatory-@return[-void] DocBlock sniffs that would
otherwise collide. Reformat existing sources accordingly.

phpstan: add a self-check rule requiring a native type hint on every class
constant (PHP 8.3+), with a RuleTestCase and Good/Bad fixtures. Registered in
tests/phpstan.neon only, so it self-enforces this package's own src/ and is not
exported to consumers via extension.neon.
@stereomon
stereomon changed the base branch from master to feature/cc-39568-suite-architecture-rules July 20, 2026 12:00
…ure-rules' into feature/cc-39568-enforce-typed-consts-no-redundant-docblocks

# Conflicts:
#	tests/Rules/Spryker/DynamicMethodMissingPhpDocAnnotationRuleTest.php
@stereomon
stereomon marked this pull request as ready for review July 20, 2026 12:34
@stereomon
stereomon merged commit f3f1793 into feature/cc-39568-suite-architecture-rules Jul 20, 2026
6 checks passed
@stereomon
stereomon deleted the feature/cc-39568-enforce-typed-consts-no-redundant-docblocks branch July 20, 2026 12:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants