Skip to content

Conversation

@Dylan-DPC-zz
Copy link

removed unnecessary assignment of

$data = $data;

$data = $data->toArray();
} elseif ($data instanceof JsonSerializable) {
$data = $data->jsonSerialize();
if (! is_array($data)) {
Copy link
Contributor

@ntzm ntzm Nov 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we just remove this check completely?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't that be a breaking change? I kept it because it matched the behaviour before removing it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would it break anything? The other two checks don't match arrays

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know..but didn't want to risk it incase there is any edge case.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no cases where an instance of Collection, Arrayable or JsonSerializable will pass is_array

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i know.. but these things often have some weird edge cases 😆

} elseif ($data instanceof JsonSerializable) {
$data = $data->jsonSerialize();
}
if ($data instanceof Arrayable || $data instanceof Collection) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if ($data instanceof Arrayable) {

The Collection class already implements the Arrayable interface.

@devcircus
Copy link
Contributor

Someone tried refactoring this method a few weeks ago and Taylor responded: #21526 (comment)

@Dylan-DPC-zz Dylan-DPC-zz deleted the fix/resource branch November 18, 2017 05:34
@jordyvandomselaar
Copy link

You'd think they cared more for quality code.

@deleugpn
Copy link
Contributor

@jordyvandomselaar when you're alone handling dozens of weekly PRs changing the code used by millions of people around the globe everyday, striving not to introduce new bugs or useless breaking changes, it's completely understandable why small changes like these gets ignored.

@devcircus
Copy link
Contributor

Absolutely. They've been burned many times by seemingly innocent small changes meant to improve readability.

@Dylan-DPC-zz
Copy link
Author

Ironically we have had breaking changes and other bugs from more feature code than readability fixes. The code was structured keeping that in mind that it doesn't change any behaviour any introduce further bugs. By this logic we shouldn't be doing code refactorings at all and we know how that goes.

Also I know there are a lot of PRs coming in everyday, but there is no hurry to merge them quickly.

@jordyvandomselaar
Copy link

Having many PR's shouldn't be an excuse to keep low quality code lingering around. PR's like these could be put on low priority for someone else to do in their spare time. Refactoring old code doesn't only make things more readable, it also makes it less likely to break when adding new features or fixing other bugs. It'd be a shame if the entire core fell flat because some old code isn't behaving the way it should.

You could create a test branch where things get merged provided they have proper unit tests, so the community can test the framework. It'd be like a beta. Then, anyone on the team can test it thoroughly before it makes it to master.

@deleugpn
Copy link
Contributor

@jordyvandomselaar If you find a low-quality code, please do open a PR for people to look over. This PR isn't the case. This isn't a low-quality code. It's clear and readable. There has been some great refactoring PRs that got merged for those reasons you pointed out.

As per your thoughts on how it should be done, that's not how the Laravel ecosystem is maintained.

@Dylan-DPC-zz
Copy link
Author

Duh. We know that's not how the Laravel ecosystem is maintained that's why we are pointing it out 😛

@jordyvandomselaar
Copy link

Useless code equals low quality code.

And, just because that's not how it's done right now doesn't mean it shouldn't ever happen. It would benefit the framework, and you with it.

@deleugpn
Copy link
Contributor

deleugpn commented Nov 19, 2017

@jordyvandomselaar this is precisely one of the great reasons I see Taylor closing these kinds of PR. Opinionated. You think the code is useless, I don't. For instance, this version of the refactoring doesn't have the useless code, yet it's less readable.

@Dylan-DPC-zz
Copy link
Author

That code may be readable, but the change isn't comprising on its readability. Also I showed the original code.

You think the code is useless, I don't.

Even Phpstorm complains that it is useless.

@jordyvandomselaar
Copy link

The code being useless isn't entirely opinion based. It really doesn't do anything at all. It doesn't make it more readable, it doesn't make things more performant, it doesn't fix anything; it does absolutely nothing at all.

Not trying to get personal here, but it seems you're more opinionated on this than anyone. Reason it feels like that is because you're defending code that should never have existed in the first place.

@deleugpn
Copy link
Contributor

it doesn't make it more readable.

The useless code is more readable than this. The final version of this PR I would agree that ended up being better than the current implementation, but the point I'm trying to make is about 2 lines of refactoring in general. The risks outweight the benefits.

@jordyvandomselaar
Copy link

That I can agree with. I'll see what I can cook up sometime, or leave it alltogether. This case in particular doesn't bother me too much; the explanation given for it not to be merged annoys me.

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.

8 participants