Skip to content

[symfony] Skip data holders with public properties in "NoNullableServiceInConstructorRule" - #335

Merged
TomasVotruba merged 1 commit into
symplify:mainfrom
bmdevel:skip-public-property-data-holders
Oct 2, 2026
Merged

TomasVotruba merged 1 commit into
symplify:mainfrom
bmdevel:skip-public-property-data-holders

Conversation

@bmdevel

@bmdevel bmdevel commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

NoNullableServiceInConstructorRule skips data holders only by namespace (\Entity\, \DTO\, \Dto\, \ValueObject\, …). Value objects in other namespaces are reported, for example a domain model that holds optional data:

namespace App\Domain\Model\Offers;

final readonly class Price
{
    public function __construct(
        public Money $total,
        public ?Money $calculated, // reported
    ) {
    }
}

A service does not expose its dependencies as public properties. So a class with public instance properties holds data, and its nullable constructor parameters are optional values. This PR skips such classes. Own, promoted and inherited public properties count, so a child class that passes values to a data-holder parent is skipped too. Static properties do not count.

The existing ReportNullableService fixture (private promoted services) is still reported. 2 new fixtures cover a promoted public property and a child of a public-property parent; both were reported before the change. The full suite, ECS, PHPStan and Rector pass.

…iceInConstructorRule"

A service does not expose its dependencies as public properties, so a
class with public instance properties (own, promoted or inherited) holds
data, and its nullable constructor parameters are optional values. This
covers value objects outside the skipped namespace list, for example in
a "Model" namespace.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@TomasVotruba
TomasVotruba merged commit 4245328 into symplify:main Oct 2, 2026
8 checks passed
@TomasVotruba

Copy link
Copy Markdown
Member

LGTM

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