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

[9.x] Add null typing to connection property in \Illuminate\Database\Eloquent\Factories\Factory #41418

Merged
merged 3 commits into from Mar 10, 2022

Conversation

jnoordsij
Copy link
Contributor

When extending the Factory in my application, using a null coalescing operator on $this->connection and running static analysis using Larastan, I got an error Property Illuminate\Database\Eloquent\Factories\Factory<Illuminate\Database\Eloquent\Model>::$connection (string) in isset() is not nullable.

However, the constructor by defaults sets $this->connection = null;. Similarly, there are some other nullable properties. This PR fixes the docstring typehints on these properties.

@driesvints
Copy link
Member

Most of these can never be null. They're always filled in through the object's constructor. I don't think we should adjust this for extending classes.

@jnoordsij
Copy link
Contributor Author

Ah nevermind, I was being too quick to judge about most of them. Only the connection can really be null after the constructor. I'll adjust them.

Might as well use null coalescing operators in the constructor for the others?

@jnoordsij jnoordsij changed the title [9.x] Add null typing to nullable properties in \Illuminate\Database\Eloquent\Factories\Factory [9.x] Add null typing to connection property in \Illuminate\Database\Eloquent\Factories\Factory Mar 10, 2022
@taylorotwell taylorotwell merged commit c3195b3 into laravel:9.x Mar 10, 2022
@jnoordsij jnoordsij deleted the fix-factory-connection-docstrings branch March 10, 2022 16:49
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.

None yet

3 participants