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

Fix setting value for an attribute when AR class has get method for the attribute #274

Merged
merged 3 commits into from
Dec 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/BaseActiveRecordTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@
return $this->$getter();
}

if (method_exists($this, 'set' . ucfirst($name))) {

Check warning on line 79 in src/BaseActiveRecordTrait.php

View workflow job for this annotation

GitHub Actions / PHP 8-ubuntu-latest

Escaped Mutant for Mutator "UnwrapUcFirst": --- Original +++ New @@ @@ /** read property, e.g. getName() */ return $this->{$getter}(); } - if (method_exists($this, 'set' . ucfirst($name))) { + if (method_exists($this, 'set' . $name)) { throw new InvalidCallException('Getting write-only property: ' . static::class . '::' . $name); } throw new UnknownPropertyException('Getting unknown property: ' . static::class . '::' . $name);
throw new InvalidCallException('Getting write-only property: ' . static::class . '::' . $name);
}

throw new UnknownPropertyException('Getting unknown property: ' . static::class . '::' . $name);

Check warning on line 83 in src/BaseActiveRecordTrait.php

View workflow job for this annotation

GitHub Actions / PHP 8-ubuntu-latest

Escaped Mutant for Mutator "ConcatOperandRemoval": --- Original +++ New @@ @@ if (method_exists($this, 'set' . ucfirst($name))) { throw new InvalidCallException('Getting write-only property: ' . static::class . '::' . $name); } - throw new UnknownPropertyException('Getting unknown property: ' . static::class . '::' . $name); + throw new UnknownPropertyException(static::class . '::' . $name); } /** * Returns the relation object with the specified name.
}

/**
Expand Down Expand Up @@ -200,6 +200,7 @@
$this->resetDependentRelations($name);
}
$this->attributes[$name] = $value;
return;
}

if (method_exists($this, 'get' . ucfirst($name))) {
Expand Down Expand Up @@ -252,7 +253,7 @@
* @param mixed $offset the offset to set element.
* @param mixed $item the element value.
*/
public function offsetSet(mixed $offset, mixed $item): void

Check failure on line 256 in src/BaseActiveRecordTrait.php

View workflow job for this annotation

GitHub Actions / PHP 8.1-ubuntu-latest

ParamNameMismatch: Argument 2 of Yiisoft\ActiveRecord\BaseActiveRecordTrait::offsetSet has wrong name $item, expecting $value as defined by ArrayAccess::offsetSet

Check failure on line 256 in src/BaseActiveRecordTrait.php

View workflow job for this annotation

GitHub Actions / PHP 8.1-ubuntu-latest

ParamNameMismatch: Argument 2 of Yiisoft\ActiveRecord\BaseActiveRecordTrait::offsetSet has wrong name $item, expecting $value as defined by ArrayAccess::offsetSet
{
$this->$offset = $item;
}
Expand Down
5 changes: 5 additions & 0 deletions tests/Stubs/ActiveRecord/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ public function getTableName(): string
return 'customer';
}

public function getName(): string
{
return $this->getAttribute('name');
}

public function getProfile(): ActiveQuery
{
return $this->hasOne(Profile::class, ['id' => 'profile_id']);
Expand Down
Loading