2929use CodeIgniter \Exceptions \InvalidArgumentException ;
3030
3131/**
32- * @template TCastHandlers of array<string, CastInterface|class-string|EntityCastInterface>
32+ * @phpstan-type cast_handlers array<string, CastInterface|class-string|EntityCastInterface>
3333 *
3434 * @see CodeIgniter\DataCaster\DataCasterTest
3535 * @see CodeIgniter\Entity\EntityTest
@@ -46,7 +46,8 @@ final class DataCaster
4646 /**
4747 * Convert handlers.
4848 *
49- * @var TCastHandlers [type => classname]
49+ * @var array<string, class-string> [type => classname]
50+ * @phpstan-var cast_handlers
5051 */
5152 private array $ castHandlers = [
5253 'array ' => ArrayCast::class,
@@ -65,20 +66,19 @@ final class DataCaster
6566 ];
6667
6768 /**
68- * @param TCastHandlers|null $castHandlers Custom convert handlers
69- * @param array<string, string>|null $types [field => type]
70- * @param object|null $helper Helper object.
71- * @param bool $strict Strict mode? Set to false for casts for Entity.
69+ * @param array<string, class-string>|null $castHandlers Custom convert handlers
70+ * @param array<string, string>|null $types [field => type]
71+ * @param object|null $helper Helper object.
72+ * @param bool $strict Strict mode? Set to false for casts for Entity.
73+ * @phpstan-param cast_handlers|null $castHandlers
7274 */
7375 public function __construct (
7476 ?array $ castHandlers = null ,
7577 ?array $ types = null ,
7678 private readonly ?object $ helper = null ,
7779 private readonly bool $ strict = true ,
7880 ) {
79- if ($ castHandlers !== null && $ castHandlers !== []) {
80- $ this ->castHandlers = array_merge ($ this ->castHandlers , $ castHandlers );
81- }
81+ $ this ->castHandlers = array_merge ($ this ->castHandlers , $ castHandlers ?? []);
8282
8383 if ($ types !== null ) {
8484 $ this ->setTypes ($ types );
@@ -121,9 +121,9 @@ public function setTypes(array $types): static
121121 * Add ? at the beginning of the type (i.e. ?string) to get `null`
122122 * instead of casting $value when $value is null.
123123 *
124- * @param mixed $value The value to convert
125- * @param string $field The field name
126- * @param 'get'|'set' $method Allowed to "get" and "set"
124+ * @param mixed $value The value to convert
125+ * @param string $field The field name
126+ * @param string $method Allowed to "get" and "set"
127127 */
128128 public function castAs (mixed $ value , string $ field , string $ method = 'get ' ): mixed
129129 {
0 commit comments