Skip to content

Commit 6a131bd

Browse files
committed
fix: Apply suggestion
1 parent de28579 commit 6a131bd

File tree

3 files changed

+13
-16
lines changed

3 files changed

+13
-16
lines changed

system/DataCaster/DataCaster.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
use 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
{

system/Entity/Cast/BaseCast.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313

1414
namespace CodeIgniter\Entity\Cast;
1515

16-
/**
17-
* Class BaseCast.
18-
*/
1916
abstract class BaseCast implements CastInterface
2017
{
2118
public static function get($value, array $params = [])

tests/system/DataCaster/DataCasterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ public function testCastInvalidMethodException(): void
2929
$this->expectExceptionMessage('The "add" is invalid cast method, valid methods are: ["get", "set"].');
3030

3131
$dataCaster = new DataCaster();
32-
$dataCaster->castAs([], 'name', 'add'); // @phpstan-ignore argument.type
32+
$dataCaster->castAs([], 'name', 'add');
3333
}
3434
}

0 commit comments

Comments
 (0)