Skip to content

[OLYMPUS-1470]: Convert the settings class property defaults test into a common PHPStan rule#119

Merged
Orrison merged 3 commits into
mainfrom
feature/settings-properties-must-have-defaults-rule
Jul 13, 2026
Merged

[OLYMPUS-1470]: Convert the settings class property defaults test into a common PHPStan rule#119
Orrison merged 3 commits into
mainfrom
feature/settings-properties-must-have-defaults-rule

Conversation

@mittal-canyon

Copy link
Copy Markdown
Contributor

Ticket(s) or GitHub Issue

Technical Description

Enforces that all properties in Spatie Settings subclasses declare a
PHP default value. Without a default, PHP reflection returns null
regardless of the declared type, causing silent type errors at runtime
when the value has not yet been persisted.

  • Add SettingsPropertiesMustHaveDefaultsRule (Property node, isSubclassOf guard)
  • Register rule in phpstan-extension.neon
  • Add fixtures: SettingsWithDefaults, SettingsWithoutDefaults, NonSettingsWithoutDefaults
  • Add SettingsPropertiesMustHaveDefaultsTest

Any deployment steps required?

NO

Are any Feature Flags and/or Data Migrations that can eventually be removed added?

NO


Before contributing and submitting this PR, make sure you have Read, agree, and are compliant with the contributing guidelines.

@mittal-canyon
mittal-canyon requested a review from a team as a code owner July 10, 2026 13:25
@mittal-canyon mittal-canyon added the php Pull requests that update php code label Jul 10, 2026
@mittal-canyon
mittal-canyon marked this pull request as draft July 10, 2026 13:25
@mittal-canyon
mittal-canyon force-pushed the feature/settings-properties-must-have-defaults-rule branch from c6de145 to 4a3aa5e Compare July 10, 2026 13:30
@mittal-canyon
mittal-canyon requested review from Orrison and Copilot and removed request for Copilot and payal-canyon July 10, 2026 13:32
@mittal-canyon
mittal-canyon force-pushed the feature/settings-properties-must-have-defaults-rule branch from c6aa9d4 to 7222054 Compare July 10, 2026 13:51
@mittal-canyon
mittal-canyon marked this pull request as ready for review July 10, 2026 14:01
mittal-canyon and others added 3 commits July 13, 2026 16:01
- Remove redundant getName() !== check from guard condition;
  isSubclassOf() already returns false for the class itself, and
  PHPStan flags the class-string strict comparison as always-true
- Add tests/PHPStan/Configs/settings-properties-must-have-defaults.neon
  following the per-rule config pattern used by all other rule tests
- Update test helper to reference the new config instead of phpstan-test.neon
@Orrison
Orrison force-pushed the feature/settings-properties-must-have-defaults-rule branch from 92ce5df to 107e0c4 Compare July 13, 2026 20:01
@Orrison
Orrison merged commit e7ef5f0 into main Jul 13, 2026
5 checks passed
@Orrison
Orrison deleted the feature/settings-properties-must-have-defaults-rule branch July 13, 2026 20:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

php Pull requests that update php code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants