Skip to content

Commit 43df169

Browse files
committed
refactor: Improve phpDoc, typos
1 parent 12cf2b4 commit 43df169

1 file changed

Lines changed: 28 additions & 25 deletions

File tree

system/Entity/Entity.php

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
use CodeIgniter\Entity\Cast\URICast;
3131
use CodeIgniter\Entity\Exceptions\CastException;
3232
use CodeIgniter\I18n\Time;
33-
use DateTime;
3433
use DateTimeInterface;
3534
use Exception;
3635
use JsonSerializable;
@@ -79,14 +78,14 @@ class Entity implements JsonSerializable
7978
protected $casts = [];
8079

8180
/**
82-
* Custom convert handlers
81+
* Custom convert handlers.
8382
*
8483
* @var array<string, string>
8584
*/
8685
protected $castHandlers = [];
8786

8887
/**
89-
* Default convert handlers
88+
* Default convert handlers.
9089
*
9190
* @var array<string, string>
9291
*/
@@ -131,17 +130,19 @@ class Entity implements JsonSerializable
131130
protected DataCaster $dataCaster;
132131

133132
/**
134-
* Holds info whenever properties have to be casted
133+
* Holds info whenever properties have to be casted.
135134
*/
136135
private bool $_cast = true;
137136

138137
/**
139-
* Indicates whether all attributes are scalars (for optimization)
138+
* Indicates whether all attributes are scalars (for optimization).
140139
*/
141140
private bool $_onlyScalars = true;
142141

143142
/**
144143
* Allows filling in Entity parameters during construction.
144+
*
145+
* @param array<string, mixed> $data
145146
*/
146147
public function __construct(?array $data = null)
147148
{
@@ -162,7 +163,7 @@ public function __construct(?array $data = null)
162163
* properties, using any `setCamelCasedProperty()` methods
163164
* that may or may not exist.
164165
*
165-
* @param array<string, array|bool|float|int|object|string|null> $data
166+
* @param array<string, array<int|string, mixed>|bool|float|int|object|string|null> $data
166167
*
167168
* @return $this
168169
*/
@@ -184,9 +185,11 @@ public function fill(?array $data = null)
184185
* of this entity as an array. All values are accessed through the
185186
* __get() magic method so will have any casts, etc applied to them.
186187
*
187-
* @param bool $onlyChanged If true, only return values that have changed since object creation
188+
* @param bool $onlyChanged If true, only return values that have changed since object creation.
188189
* @param bool $cast If true, properties will be cast.
189190
* @param bool $recursive If true, inner entities will be cast as array as well.
191+
*
192+
* @return array<string, mixed>
190193
*/
191194
public function toArray(bool $onlyChanged = false, bool $cast = true, bool $recursive = false): array
192195
{
@@ -227,8 +230,10 @@ public function toArray(bool $onlyChanged = false, bool $cast = true, bool $recu
227230
/**
228231
* Returns the raw values of the current attributes.
229232
*
230-
* @param bool $onlyChanged If true, only return values that have changed since object creation
233+
* @param bool $onlyChanged If true, only return values that have changed since object creation.
231234
* @param bool $recursive If true, inner entities will be cast as array as well.
235+
*
236+
* @return array<string, mixed>
232237
*/
233238
public function toRawArray(bool $onlyChanged = false, bool $recursive = false): array
234239
{
@@ -370,8 +375,6 @@ public function syncOriginal()
370375
* Checks a property to see if it has changed since the entity
371376
* was created. Or, without a parameter, checks if any
372377
* properties have changed.
373-
*
374-
* @param string|null $key class property
375378
*/
376379
public function hasChanged(?string $key = null): bool
377380
{
@@ -500,7 +503,9 @@ private function normalizeValue(mixed $data): mixed
500503
}
501504

502505
/**
503-
* Set raw data array without any mutations
506+
* Set raw data array without any mutations.
507+
*
508+
* @param array<string, mixed> $data
504509
*
505510
* @return $this
506511
*/
@@ -514,7 +519,7 @@ public function injectRawData(array $data)
514519
}
515520

516521
/**
517-
* Set raw data array without any mutations
522+
* Set raw data array without any mutations.
518523
*
519524
* @return $this
520525
*
@@ -527,28 +532,28 @@ public function setAttributes(array $data)
527532

528533
/**
529534
* Checks the datamap to see if this property name is being mapped,
530-
* and returns the db column name, if any, or the original property name.
535+
* and returns the DB column name, if any, or the original property name.
531536
*
532-
* @return string db column name
537+
* @return string Database column name.
533538
*/
534539
protected function mapProperty(string $key)
535540
{
536541
if ($this->datamap === []) {
537542
return $key;
538543
}
539544

540-
if (! empty($this->datamap[$key])) {
545+
if (array_key_exists($key, $this->datamap) && $this->datamap[$key] !== '') {
541546
return $this->datamap[$key];
542547
}
543548

544549
return $key;
545550
}
546551

547552
/**
548-
* Converts the given string|timestamp|DateTime|Time instance
553+
* Converts the given string|timestamp|DateTimeInterface|Time instance
549554
* into the "CodeIgniter\I18n\Time" object.
550555
*
551-
* @param DateTime|float|int|string|Time $value
556+
* @param DateTimeInterface|float|int|string|Time $value
552557
*
553558
* @return Time
554559
*
@@ -568,7 +573,7 @@ protected function mutateDate($value)
568573
* @param string $attribute Attribute name
569574
* @param string $method Allowed to "get" and "set"
570575
*
571-
* @return array|bool|float|int|object|string|null
576+
* @return array<int|string, mixed>|bool|float|int|object|string|null
572577
*
573578
* @throws CastException
574579
*/
@@ -581,9 +586,9 @@ protected function castAs($value, string $attribute, string $method = 'get')
581586
}
582587

583588
/**
584-
* Support for json_encode()
589+
* Support for json_encode().
585590
*
586-
* @return array
591+
* @return array<string, mixed>
587592
*/
588593
#[ReturnTypeWillChange]
589594
public function jsonSerialize()
@@ -592,7 +597,7 @@ public function jsonSerialize()
592597
}
593598

594599
/**
595-
* Change the value of the private $_cast property
600+
* Change the value of the private $_cast property.
596601
*
597602
* @return bool|Entity
598603
*/
@@ -616,7 +621,7 @@ public function cast(?bool $cast = null)
616621
* $this->my_property = $p;
617622
* $this->setMyProperty() = $p;
618623
*
619-
* @param array|bool|float|int|object|string|null $value
624+
* @param array<int|string, mixed>|bool|float|int|object|string|null $value
620625
*
621626
* @return void
622627
*
@@ -667,11 +672,9 @@ public function __set(string $key, $value = null)
667672
* $p = $this->my_property
668673
* $p = $this->getMyProperty()
669674
*
670-
* @return array|bool|float|int|object|string|null
675+
* @return array<int|string, mixed>|bool|float|int|object|string|null
671676
*
672677
* @throws Exception
673-
*
674-
* @params string $key class property
675678
*/
676679
public function __get(string $key)
677680
{

0 commit comments

Comments
 (0)