Skip to content

[5.6] Extract setting mutated attribute into method#24307

Merged
taylorotwell merged 1 commit into
laravel:5.6from
mnabialek:5.6-extract-method
May 25, 2018
Merged

[5.6] Extract setting mutated attribute into method#24307
taylorotwell merged 1 commit into
laravel:5.6from
mnabialek:5.6-extract-method

Conversation

@mnabialek
Copy link
Copy Markdown
Contributor

When dealing with accessors, code looks like now like this:

if ($this->hasGetMutator($key)) {
    return $this->mutateAttribute($key, $value);
}

so in case of custom method functionality, it's possible to override both hasGetMutator and mutateAttribute for custom code.

But for mutator code looked so far like this:

if ($this->hasSetMutator($key)) {
    $method = 'set'.Str::studly($key).'Attribute';

    return $this->{$method}($value);
}

so it's impossible to do similar change for mutator. In fact you need to override the whole setAttribute method just to make similar change because setting mutated attribute is not extracted to external method.

After this PR code for mutator condition would look like this:

if ($this->hasSetMutator($key)) {
    return $this->setMutatedAttributeValue($key, $value);
}

so now it would be enough just to override those 2 methods instead of touching setAttribute code. Also code is more consistent now I believe.

@taylorotwell taylorotwell merged commit 5837438 into laravel:5.6 May 25, 2018
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.

2 participants