8000 [12.x] Set class-string generics on `Enum` rule by cosmastech · Pull Request #55588 · laravel/framework · GitHub
[go: up one dir, main page]

Skip to content
/ framework < 8000 span class="Label Label--secondary v-align-middle mr-1">Public

[12.x] Set class-string generics on Enum rule #55588

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into 8000 from
Apr 29, 2025

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
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0