Skip to content

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

Merged
taylorotwell merged 3 commits into
laravel:9.xfrom
jnoordsij:fix-factory-connection-docstrings
Mar 10, 2022
Merged

[9.x] Add null typing to connection property in \Illuminate\Database\Eloquent\Factories\Factory#41418
taylorotwell merged 3 commits into
laravel:9.xfrom
jnoordsij:fix-factory-connection-docstrings

Conversation

@jnoordsij

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

3 participants