Skip to content
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

Add generics to WithMapping #4021

Merged
merged 1 commit into from
Nov 1, 2023

Conversation

joelharkes
Copy link
Contributor

@joelharkes joelharkes commented Oct 30, 2023

Please take note of our contributing guidelines: https://docs.laravel-excel.com/3.1/getting-started/contributing.html
Filling out the template is required. Any pull request that does not include enough information to be reviewed in a timely manner may be closed at the maintainers' discretion.

1️⃣ Why should it be added? What are the benefits of this change?

Adding more typesaftey and benefit of static analyzer.

Before:
image

After

/**
 * @implements WithMapping<MyModel>
*/
class MyExport {
    public function map($row){
       // IDE Knows the right type now = MyModel.
   }
}

2️⃣ Does it contain multiple, unrelated changes? Please separate the PRs out.

No i just started by adding type safety to WithMapping, i could add it for all FromX iterfaces as well but i wouldnt want to make it too big at once.
First i would like to check if you like this before i added generic types everywhere.

3️⃣ Does it include tests, if possible?

No it's just doctype

4️⃣ Any drawbacks? Possible breaking changes?

No breaking changes, no effect on any existing code, even static analyzer with by default assume mixed type.

5️⃣ Mark the following tasks as done:

  • Checked the codebase to ensure that your feature doesn't already exist.
  • Take note of the contributing guidelines.
  • Checked the pull requests to ensure that another person hasn't already submitted a fix.
  • Added tests to ensure against regression. => No testing needed i think?

6️⃣ Thanks for contributing! 🙌

🥳

@patrickbrouwers
Copy link
Member

patrickbrouwers commented Oct 30, 2023

Love this, thanks!

Which other concerns you have in mind that are relevant for generics? I wouldn't mind if you add some more to this PR.

@joelharkes
Copy link
Contributor Author

FromQuery => can be type generic based on Builder
FromCollection / FromArray / FromIterator

All the ToX interfaces as well.

I prefer merging this first as this is the most problematic for Lara/PHPStan.
and make a separate PR for the others

@patrickbrouwers patrickbrouwers merged commit 7d1ee0f into SpartnerNL:3.1 Nov 1, 2023
16 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