orm: set return static

This commit is contained in:
Yuri Kuznetsov
2024-11-09 11:46:52 +02:00
parent da9c346fa8
commit 04518fbb78
3 changed files with 23 additions and 16 deletions
+5 -3
View File
@@ -77,7 +77,7 @@ class Integration extends Entity
$this->set('data', $data);
}
public function set($p1, $p2 = null): void
public function set($p1, $p2 = null): static
{
if (is_object($p1)) {
$p1 = get_object_vars($p1);
@@ -90,7 +90,7 @@ class Integration extends Entity
$this->populateFromArray($p1, $p2);
return;
return $this;
}
$name = $p1;
@@ -99,7 +99,7 @@ class Integration extends Entity
if ($name == 'id') {
$this->id = $value;
return;
return $this;
}
if ($this->hasAttribute($name)) {
@@ -111,6 +111,8 @@ class Integration extends Entity
$this->set('data', $data);
}
return $this;
}
public function isAttributeChanged(string $name): bool
+13 -9
View File
@@ -154,7 +154,7 @@ class BaseEntity implements Entity
* @param string|stdClass|array<string, mixed> $attribute
* @param mixed $value
*/
public function set($attribute, $value = null): void
public function set($attribute, $value = null): static
{
$p1 = $attribute;
$p2 = $value;
@@ -183,7 +183,7 @@ class BaseEntity implements Entity
$this->populateFromArray($p1, $p2);
return;
return $this;
}
if (is_string($p1)) {
@@ -194,7 +194,7 @@ class BaseEntity implements Entity
}
if (!$this->hasAttribute($name)) {
return;
return $this;
}
$method = '_set' . ucfirst($name);
@@ -202,14 +202,14 @@ class BaseEntity implements Entity
if (method_exists($this, $method)) {
$this->$method($value);
return;
return $this;
}
$this->populateFromArray([
$name => $value,
]);
return;
return $this;
}
throw new InvalidArgumentException();
@@ -221,9 +221,9 @@ class BaseEntity implements Entity
* @param array<string, mixed>|stdClass $valueMap Values.
* @since v8.1.0.
*/
public function setMultiple(array|stdClass $valueMap): void
public function setMultiple(array|stdClass $valueMap): static
{
$this->set($valueMap);
return $this->set($valueMap);
}
/**
@@ -435,13 +435,15 @@ class BaseEntity implements Entity
*
* @throws RuntimeException
*/
public function setValueObject(string $field, ?object $value): void
public function setValueObject(string $field, ?object $value): static
{
if (!$this->valueAccessor) {
throw new RuntimeException("No ValueAccessor.");
}
$this->valueAccessor->set($field, $value);
return $this;
}
/**
@@ -936,11 +938,13 @@ class BaseEntity implements Entity
/**
* Set a fetched value for a specific attribute.
*/
public function setFetched(string $attribute, $value): void
public function setFetched(string $attribute, $value): static
{
$preparedValue = $this->prepareAttributeValue($attribute, $value);
$this->fetchedValuesContainer[$attribute] = $preparedValue;
return $this;
}
/**
+5 -4
View File
@@ -31,6 +31,7 @@ namespace Espo\ORM;
use Espo\ORM\Type\AttributeType;
use Espo\ORM\Type\RelationType;
use RuntimeException;
use stdClass;
/**
@@ -64,7 +65,7 @@ interface Entity
* Get an entity ID.
*
* @return non-empty-string
* @throws \RuntimeException If an ID is not set.
* @throws RuntimeException If an ID is not set.
*/
public function getId(): string;
@@ -88,7 +89,7 @@ interface Entity
* @param string|stdClass|array<string, mixed> $attribute
* @param mixed $value
*/
public function set($attribute, $value = null): void;
public function set($attribute, $value = null): static;
/**
* Set multiple attributes.
@@ -96,7 +97,7 @@ interface Entity
* @param array<string, mixed>|stdClass $valueMap Values.
* @since v8.1.0.
*/
public function setMultiple(array|stdClass $valueMap): void;
public function setMultiple(array|stdClass $valueMap): static;
/**
* Get an attribute value.
@@ -192,7 +193,7 @@ interface Entity
*
* @param mixed $value
*/
public function setFetched(string $attribute, $value): void;
public function setFetched(string $attribute, $value): static;
/**
* Get values.