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

Respect Laravel's new accessors #2394

Closed
wants to merge 1 commit into from
Closed

Conversation

mrneatly
Copy link
Contributor

Fix getting a value from \Illuminate\Database\Eloquent\Casts\Attribute-returning accessors (issue #2363).

Fix getting a value from a one-word `\Illuminate\Database\Eloquent\Casts\Attribute`-returning accessors
@codecov-commenter
Copy link

codecov-commenter commented May 28, 2022

Codecov Report

Merging #2394 (5a5eb96) into master (f4c448f) will increase coverage by 0.01%.
The diff coverage is 100.00%.

❗ Current head 5a5eb96 differs from pull request most recent head 5d292a2. Consider uploading reports for the commit 5d292a2 to get more accurate results

@@             Coverage Diff              @@
##             master    #2394      +/-   ##
============================================
+ Coverage     87.62%   87.63%   +0.01%     
- Complexity      676      677       +1     
============================================
  Files            31       31              
  Lines          1551     1553       +2     
============================================
+ Hits           1359     1361       +2     
  Misses          192      192              
Impacted Files Coverage Δ
src/Eloquent/Model.php 93.71% <100.00%> (+0.08%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@Smolevich Smolevich self-requested a review May 28, 2022 08:49
@CraigMonva
Copy link

Whats the status of this PR?

@mrneatly
Copy link
Contributor Author

I've managed to fix the issue, but the cs-fixer denied my code for some reason. As the code in php-cs-fixer details doesn't give any clue, I would be very happy if anyone could explain me, what exactly I have to fix in order to have my pull request accepted :)

@divine
Copy link
Contributor

divine commented Jul 12, 2022

This is a breaking change and is this related to embedded relation?

@mrneatly
Copy link
Contributor Author

mrneatly commented Jul 25, 2022

@divine this change isn't specifically related to an embedded relation as this case may also happen when using other types of relations. I'm not sure if it's really a breaking change because all this code does is performs an additional check whether requested attribute returns an Attribute object or not. Without that change, a null s being returned in case of a one-worded attribute, which is obviously a bug.

@@ -155,8 +155,12 @@ public function getAttribute($key)
}

// This checks for embedded relation support.
if (method_exists($this, $key) && ! method_exists(self::class, $key)) {
return $this->getRelationValue($key);
if (
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (
if (
method_exists($this, $key)
&& !method_exists(self::class, $key)
&& !$this->hasAttributeGetMutator($key)
) {
return $this->getRelationValue($key);

This should fix your formatting so that PHP-CS-Fixer passes

@divine
Copy link
Contributor

divine commented Aug 31, 2022

Closed in favor of #2438.

@divine divine closed this Aug 31, 2022
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

5 participants