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

feat: property check on dynamic wheres #686

Merged
merged 1 commit into from
Oct 16, 2020

Conversation

canvural
Copy link
Collaborator

@canvural canvural commented Oct 15, 2020

  • Added or updated tests
  • Documented user facing changes
  • Updated CHANGELOG.md

This PR adds support for model property check to dynamic wheres. For example

User::whereIdAndEmaiil(...)->get();

would produce an error. Because while id exists as a property on User class, emaiil does not.

This does not produce the same error message as our property check rule. It will just complain about that method not exists in the class. I guess this is ok. Developers will see the missing method error and can figure out it's coming from a missing property.

The one thing I wasn't certain about is, should this check be also under the checkModelProperties flag? I think it should. Or maybe a new flag like checkPropertiesonDynamicWheres?

@canvural canvural force-pushed the property-check-on-dynamic-where branch from 609f71e to 0577054 Compare October 15, 2020 17:50
@canvural canvural added the enhancement New feature or request label Oct 15, 2020
@canvural canvural force-pushed the property-check-on-dynamic-where branch from 0301c54 to cb913fb Compare October 16, 2020 14:55
@canvural canvural merged commit aa4ceda into master Oct 16, 2020
@canvural canvural deleted the property-check-on-dynamic-where branch October 16, 2020 14:56
@mfn
Copy link
Contributor

mfn commented Oct 17, 2020

But it does not check ->where<Column>(), or?

I don't use combinations but (sometimes) the above and made a deliberate error with 0.6.6 but didn't seem to get caught with checkModelProperties: true.

thanks

@canvural
Copy link
Collaborator Author

@mfn It does check those also. Can you create a new issue and share some code snippets?

@mfn
Copy link
Contributor

mfn commented Dec 2, 2020

It does check those also. Can you create a new issue and share some code snippets?

I didn't create a new issue yet, because I'm still not confident if this PR and what I suggested it truly supposed to work or not. Once this is cleared, I'm happy to 😄

But before that, please let me once more verify: it this supposed to check the (non-static!) way of invoking those methods (i.e. ->where…() or just the static ones ::where…()?

This works / no error, because there is a column profiles.type:

Profile::whereType('test');

This generates an error now in *stan (correctly 👍 ) because there's no profiles.yolo:

Profile::whereYolo('test');

produces

  57     Call to an undefined static method App\Profile::whereYolo().

But this does not generate an error (although there's no profiles.yolo column):

Profile::whereType('test')->whereYolo('test');

I'm testing this right now with phpstan 0.12.58 and larastan 0.6.10 on level 6.

Can you confirm that the last example also should throw an error from *stan?

Thank you!

@canvural
Copy link
Collaborator Author

canvural commented Dec 2, 2020

Yes Profile::whereType('test')->whereYolo('test'); should also throw error. And I guess I know why it's not working 😄 So, please create an issue, and I'll try to fix it. 👍

@mfn
Copy link
Contributor

mfn commented Dec 2, 2020

Thank you => #726

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants