Skip to content

Commit 6c5e6f2

Browse files
committed
fix: Apply suggestion
1 parent 8393661 commit 6c5e6f2

File tree

5 files changed

+28
-15
lines changed

5 files changed

+28
-15
lines changed

system/HTTP/Parameters/InputParameters.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818

1919
/**
2020
* @template TKey of string
21-
* @template TValue of bool|float|int|string|array<int|string, mixed>
21+
* @template TValue of scalar|array<(int|string), mixed>
22+
*
23+
* @extends Parameters<TKey, TValue>
2224
*
2325
* @see \CodeIgniter\HTTP\Parameters\InputParametersTest
2426
*/
@@ -33,7 +35,7 @@ public function override(array $parameters = []): void
3335
}
3436
}
3537

36-
public function get(string $key, $default = null)
38+
public function get(string $key, mixed $default = null): mixed
3739
{
3840
if ($default !== null && ! is_scalar($default)) {
3941
throw new InvalidArgumentException(sprintf('The default value for the InputParameters must be a scalar type, "%s" given.', gettype($default)));
@@ -51,7 +53,7 @@ public function get(string $key, $default = null)
5153
return $value === $tempDefault ? $default : $value;
5254
}
5355

54-
public function set(string $key, $value): void
56+
public function set(string $key, mixed $value): void
5557
{
5658
if (! is_scalar($value) && ! is_array($value)) {
5759
throw new InvalidArgumentException(sprintf('The value for the InputParameters must be a scalar type, "%s" given.', gettype($value)));

system/HTTP/Parameters/Parameters.php

+7-4
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,17 @@
1818

1919
/**
2020
* @template TKey of string
21-
* @template TValue of mixed
21+
* @template TValue
2222
*
23-
* @property array<TKey, TValue> $parameters
23+
* @implements ParametersInterface<TKey, TValue>
2424
*
2525
* @see \CodeIgniter\HTTP\Parameters\ParametersTest
2626
*/
2727
class Parameters implements ParametersInterface
2828
{
29+
/**
30+
* @param array<TKey, TValue> $parameters
31+
*/
2932
public function __construct(
3033
protected array $parameters = [],
3134
) {
@@ -41,12 +44,12 @@ public function has(string $key): bool
4144
return array_key_exists($key, $this->parameters);
4245
}
4346

44-
public function get(string $key, $default = null)
47+
public function get(string $key, mixed $default = null): mixed
4548
{
4649
return array_key_exists($key, $this->parameters) ? $this->parameters[$key] : $default;
4750
}
4851

49-
public function set(string $key, $value): void
52+
public function set(string $key, mixed $value): void
5053
{
5154
$this->parameters[$key] = $value;
5255
}

system/HTTP/Parameters/ParametersInterface.php

+7-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818

1919
/**
2020
* @template TKey of string
21-
* @template TValue of mixed
21+
* @template TValue
22+
*
23+
* @extends IteratorAggregate<TKey, TValue>
2224
*/
2325
interface ParametersInterface extends IteratorAggregate, Countable
2426
{
@@ -41,15 +43,15 @@ public function has(string $key): bool;
4143
* @param TKey $key
4244
* @param TValue $default
4345
*
44-
* @return ?TValue
46+
* @return TValue|null
4547
*/
46-
public function get(string $key, $default = null);
48+
public function get(string $key, mixed $default = null): mixed;
4749

4850
/**
4951
* @param TKey $key
5052
* @param TValue $value
5153
*/
52-
public function set(string $key, $value): void;
54+
public function set(string $key, mixed $value): void;
5355

5456
/**
5557
* @param TKey $key
@@ -59,7 +61,7 @@ public function set(string $key, $value): void;
5961
public function all(?string $key = null): array;
6062

6163
/**
62-
* @return array<int, TKey>
64+
* @return list<TKey>
6365
*/
6466
public function keys(): array;
6567
}

system/HTTP/Parameters/ServerParameters.php

+6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313

1414
namespace CodeIgniter\HTTP\Parameters;
1515

16+
/**
17+
* @template TKey of string
18+
* @template TValue
19+
*
20+
* @extends Parameters<TKey, TValue>
21+
*/
1622
class ServerParameters extends Parameters
1723
{
1824
}

tests/system/HTTP/Parameters/InputParametersTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function testGetNonScalarValues(): void
5252

5353
$this->expectException(InvalidArgumentException::class);
5454

55-
$parameters->get('undefined_throw', new stdClass());
55+
$parameters->get('undefined_throw', new stdClass()); // @phpstan-ignore argument.type
5656
}
5757

5858
public function testAttemptSetNullValues(): void
@@ -61,7 +61,7 @@ public function testAttemptSetNullValues(): void
6161

6262
$this->expectException(InvalidArgumentException::class);
6363

64-
$parameters->set('nullable', null);
64+
$parameters->set('nullable', null); // @phpstan-ignore argument.type
6565
}
6666

6767
public function testAttemptSetNonScalarValues(): void
@@ -70,7 +70,7 @@ public function testAttemptSetNonScalarValues(): void
7070

7171
$this->expectException(InvalidArgumentException::class);
7272

73-
$parameters->set('nullable', null);
73+
$parameters->set('nullable', new stdClass()); // @phpstan-ignore argument.type
7474
}
7575

7676
public function testUpdateAndSetNewValues(): void

0 commit comments

Comments
 (0)