Skip to content

Declare CompositeRule::message() as string - #14

Closed
alies-dev wants to merge 1 commit into
illuminatech:masterfrom
alies-dev:composite-rule-message-type
Closed

alies-dev wants to merge 1 commit into
illuminatech:masterfrom
alies-dev:composite-rule-message-type

Conversation

@alies-dev

Copy link
Copy Markdown
Q A
Is bugfix? ✔️
New feature? ❌
Breaks BC? ❌
Tests pass? ✔️
Fixed issues -

message() inherits string|array from the Rule contract, but it always returns the first message from the failed validator, so it is a string. Static analysers had to treat it as string|array.

$message also starts as `` instead of null, so the getter never returns `null` before `passes()` runs.

@klimov-paul klimov-paul self-assigned this Oct 21, 2026
@klimov-paul klimov-paul added the invalid This doesn't seem right label Oct 21, 2026
@klimov-paul

Copy link
Copy Markdown
Member

Rejected.

CompositeRule::message() returns null in case it is invoked before passes().
The proving unit test is following:

$rule = new DynamicCompositeRule([
            'integer',
            'min:10',
            'max:100',
        ]);

        // No `$rule->passes(...)` invocation!

        $this->assertSame(null, $rule->message());

So null can not be excluded.

it always returns the first message from the failed validator, so it is a string

This does not justifies alteration of the return type.
It is govered by the anscestor contract. If the contract will change to strict types in the future - it should be honoered as ?string|array no matter of the child class behavior.

Also behavior of the CompositeRule may change in the future, allowing return of the array as it does not contradict the contract.

@alies-dev
alies-dev deleted the composite-rule-message-type branch October 21, 2026 12:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

invalid This doesn't seem right

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants