From 04518fbb780c79d197660caa59e8da7a69eab636 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Sat, 9 Nov 2024 11:46:52 +0200 Subject: [PATCH] orm: set return static --- application/Espo/Entities/Integration.php | 8 +++++--- application/Espo/ORM/BaseEntity.php | 22 +++++++++++++--------- application/Espo/ORM/Entity.php | 9 +++++---- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/application/Espo/Entities/Integration.php b/application/Espo/Entities/Integration.php index 58fac3987d..80caf6b6e5 100644 --- a/application/Espo/Entities/Integration.php +++ b/application/Espo/Entities/Integration.php @@ -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 diff --git a/application/Espo/ORM/BaseEntity.php b/application/Espo/ORM/BaseEntity.php index 15fb97648e..bdabbae978 100644 --- a/application/Espo/ORM/BaseEntity.php +++ b/application/Espo/ORM/BaseEntity.php @@ -154,7 +154,7 @@ class BaseEntity implements Entity * @param string|stdClass|array $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|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; } /** diff --git a/application/Espo/ORM/Entity.php b/application/Espo/ORM/Entity.php index a09fae74fe..dc08a5e69f 100644 --- a/application/Espo/ORM/Entity.php +++ b/application/Espo/ORM/Entity.php @@ -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 $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|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.