Skip to content

Conversation

@cosmastech
Copy link
Contributor

@cosmastech cosmastech commented Apr 29, 2025

Adds class-string generics to the Enum rule. Will aid in static analysis.


Dear Taylor,

Lord knows you don't want to see another typehint PR.

But me, and countless others, are slaves to PHPStan. It's not enough to have PHPStan as a part of the development process and let it guide me. No... it rules my life. Every commit I make is at the mercy of the PHPStan pipeline. If I don't keep PHPStan on level 7 satisfied, I fear my children will not eat. You can't fault a man for wanting to sustain his livelihood.

And sickest of all, perhaps, is that I'm the one who added PHPStan to our pipelines. But I digress.

I hope that you can sympathize with my plight and consider this humble PR. 🙏

Kind regards,
Luke

@Rizky92
Copy link
Contributor

Rizky92 commented Apr 29, 2025

Dear god, I hope this gets merged.

So that we're not eternally fighting the demons inside static analytics

@shaedrich
Copy link
Contributor

shaedrich commented Apr 29, 2025

Wondering if this should be done like this 🤔

/*  * @template T of \UnitEnum  */ class Enum implements Rule, ValidatorAwareRule { use Conditionable; /**  * The type of the enum.  *  * @var class-string<T>  */ protected $type; // … /**  * Create a new rule instance.  *  * @param class-string<T> $type  */ public function __construct($type) { $this->type = $type; }

or even via constructor property promotion

class Enum implements Rule, ValidatorAwareRule { use Conditionable; // … /**  * Create a new rule instance.  *  * @template T of \UnitEnum  * @param class-string<T> $type  */ public function __construct(protected $type) { }

PS: You'd have good chances of winning "best PR description of the month" or so if there was such a thing 😂👍🏻

@taylorotwell taylorotwell merged commit 30aeb8a into laravel:12.x Apr 29, 2025
60 checks passed
@cosmastech cosmastech deleted the patch-11 branch April 29, 2025 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

4 participants