Skip to content

Commit 5a0d3cd

Browse files
committed
Refactor Entity.stub
1 parent d5351b1 commit 5a0d3cd

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

stubs/Models/PHP8.0/Entity/Entity.stub

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ abstract class Entity implements JsonSerializable, Arrayable
1313
/**
1414
* @return int
1515
*/
16-
abstract public function getId();
16+
abstract public function getId(): int;
1717

1818
public function __construct()
1919
{
@@ -45,7 +45,7 @@ abstract class Entity implements JsonSerializable, Arrayable
4545
* Make all variables of the object as null
4646
* @return $this
4747
*/
48-
public function clearVariables()
48+
public function clearVariables(): self
4949
{
5050
$attributes = get_object_vars($this);
5151
foreach ($attributes as $attributeName => $attributeValue) {
@@ -57,7 +57,7 @@ abstract class Entity implements JsonSerializable, Arrayable
5757
/**
5858
* @return int
5959
*/
60-
public function getPrimaryKey()
60+
public function getPrimaryKey(): int
6161
{
6262
return $this->getId();
6363
}
@@ -90,15 +90,13 @@ abstract class Entity implements JsonSerializable, Arrayable
9090
* get an Array of Changed Attributes
9191
* @return array
9292
*/
93-
public function changedAttributesName()
93+
public function changedAttributesName(): array
9494
{
9595
$changedAttributes = [];
9696
$attributes = $this->toArray();
9797
foreach ($attributes as $key => $value) {
98-
if (isset($this->originals[$key])) {
99-
if ($value != $this->originals[$key] && !((is_array($this->originals[$key]) || is_object($this->originals[$key])))) {
100-
$changedAttributes[] = $key;
101-
}
98+
if (isset($this->originals[$key]) && $value !== $this->originals[$key] && ! ((is_array($this->originals[$key]) || is_object($this->originals[$key])))) {
99+
$changedAttributes[] = $key;
102100
}
103101
}
104102
return $changedAttributes;
@@ -108,7 +106,7 @@ abstract class Entity implements JsonSerializable, Arrayable
108106
* get an Array of Changed Attributes with new values
109107
* @return array
110108
*/
111-
public function getDirty()
109+
public function getDirty(): array
112110
{
113111
$dirty = [];
114112
$attributes = $this->toArray();
@@ -124,7 +122,7 @@ abstract class Entity implements JsonSerializable, Arrayable
124122
* get an Array of Changed Attributes with original values
125123
* @return array
126124
*/
127-
public function getChanges()
125+
public function getChanges(): array
128126
{
129127
$changes = [];
130128

@@ -139,11 +137,9 @@ abstract class Entity implements JsonSerializable, Arrayable
139137
* is any attribute changed?
140138
* @return bool
141139
*/
142-
public function isDirty()
140+
public function isDirty(): bool
143141
{
144-
if (count($this->changedAttributesName()) > 0) return true;
145-
146-
return false;
142+
return count($this->changedAttributesName()) > 0;
147143
}
148144

149145
public function jsonSerialize()

0 commit comments

Comments
 (0)