Skip to content

Conversation

@Aluisio-Pires
Copy link
Contributor

Problem:
$this->string('email') returns a Stringable. In the old code we did:

return Str::transliterate(
    Str::lower($this->string('email')) . '|' . $this->ip()
);

By using the . operator to append |{$this->ip()}, the Stringable was immediately cast to a plain string. PHPStan complained because the concatenation happens without casting the Stringable object to string.
Solution:
We now keep everything as a Stringable:

return $this->string('email')
            ->lower()                       // lower-case while still a Stringable
            ->append('|'.$this->ip())      // append the IP without casting
            ->transliterate()              // transliterate on the Stringable
            ->value();                     // finally cast to string

This chains all transformations on the Stringable object and only converts to a string once, which satisfies PHPStan’s type checks.

@taylorotwell taylorotwell merged commit ff5da60 into laravel:main Aug 21, 2025
2 checks passed
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