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

[5.8] Use Null coalescing operator to refactor #27955

Merged
merged 1 commit into from
Mar 21, 2019
Merged

[5.8] Use Null coalescing operator to refactor #27955

merged 1 commit into from
Mar 21, 2019

Conversation

richardkeep
Copy link
Contributor

No description provided.

@richardkeep richardkeep changed the title Use Null coalescing operator to refactor [5.8] Use Null coalescing operator to refactor Mar 21, 2019
@taylorotwell taylorotwell merged commit 427365a into laravel:5.8 Mar 21, 2019
return $this->convertedFiles
? $this->convertedFiles
: $this->convertedFiles = $this->convertUploadedFiles($files);
return $this->convertedFiles = $this->convertedFiles ?? $this->convertUploadedFiles($files);
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this not be shortened further to just return $this->convertedFiles ?? $this->convertUploadedFiles($files);?

Copy link
Contributor Author

@richardkeep richardkeep Mar 22, 2019

Choose a reason for hiding this comment

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

No, we also want to set the value for $this->convertUploadedFiles($files) to $this->convertedFiles if it is falsy before returning.

Copy link
Contributor

Choose a reason for hiding this comment

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

@richardkeep Gotcha 🙂

@4refael
Copy link
Contributor

4refael commented Mar 23, 2019

This change may have side effects as it's not identical to the original behavior.
The correct operator to use here is the tenary operator:
return $this->convertedFiles ?: $this->convertedFiles = $this->convertUploadedFiles($files);

@driesvints
Copy link
Member

@rellect I think it's the same result in the end, right? Although your solution makes a bit more sense.

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.

5 participants