Skip to content

Commit 44dd08c

Browse files
committed
- reverted the set() and has() signatures (Deprecated implicit conversion in 8.1)
1 parent f2f6485 commit 44dd08c

6 files changed

Lines changed: 16 additions & 11 deletions

File tree

AccessorTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function get(string $index, mixed $default = null): mixed
5050
return $this->storage[$index] ?? $default;
5151
}
5252

53-
public function has(mixed $index): bool
53+
public function has(string $index): bool
5454
{
5555
return array_key_exists($index, $this->storage);
5656
}

ExtendedArguments.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function append(string $index, mixed $value): static
5858
return $this;
5959
}
6060

61-
public function has(mixed $index): bool
61+
public function has(string $index): bool
6262
{
6363
$storage = & $this->storage;
6464
foreach (explode('.', $index) as $i) {

Interfaces.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,11 @@ public function get(string $index, mixed $default = null): mixed;
102102
/**
103103
* Checks if the key exist.
104104
*
105-
* @param mixed $index The index name
105+
* @param string $index The index name
106106
*
107107
* @return bool
108108
*/
109-
public function has(mixed $index): bool;
109+
public function has(string $index): bool;
110110

111111
/**
112112
* Checks if two properties has equal values.
@@ -152,12 +152,12 @@ interface Argument extends Data
152152
* Value mutator.
153153
* Sets a value for a property.
154154
*
155-
* @param int|string $index The name of the property
155+
* @param string $index The name of the property
156156
* @param mixed $value The value
157157
*
158158
* @return static
159159
*/
160-
public function set(mixed $index, mixed $value): static;
160+
public function set(string $index, mixed $value): static;
161161

162162
/**
163163
* Imports multiple values. The existing are overridden.

MutatorTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function __set($index, $value)
2121
return $this->set($index, $value);
2222
}
2323

24-
public function set(mixed $index, mixed $value): static
24+
public function set(string $index, mixed $value): static
2525
{
2626
$this->storage[$index] = $value;
2727
return $this;

tests/ArgumentObjectTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ public function test_indirect_array_modification()
218218
public function test_some_implicit_conversion_pain($store)
219219
{
220220
// Here comes the fun...
221-
$this->assertTrue($store->has(3.14), 'Key exists? Lets see...');
221+
$this->assertFalse($store->has(3.14), 'Key DOES NOT exist. Lets see...');
222222
$this->assertNotSame('oh no', $store->get(3.14), 'Wait what? (test is false positive btw)');
223223
$this->assertSame(null, $store->get(3.14), 'I expected something else');
224224
$this->assertSame('oh no', $store->get(3), 'The amazing implicit conversion of 3.14 and the override of the existing key 3');
@@ -249,7 +249,6 @@ public function pain()
249249
'3.140' => 'yes',
250250
];
251251

252-
// using set()
253252
$store = new Arguments;
254253
foreach ($data as $index => $value) {
255254
$store->set($index, $value);

tests/ImmutableObjectTest.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,14 @@ public function test_should_transform_immutable_to_argument_object()
3737
public function test_should_get_things()
3838
{
3939
$this->assertNull($this->SUT->get('fubar'));
40-
$this->assertTrue($this->SUT->get(true));
41-
$this->assertTrue($this->SUT->has(null));
40+
41+
$this->assertTrue($this->SUT->get(true), 'All 3 are valid :(');
42+
$this->assertTrue($this->SUT->get(1));
43+
$this->assertTrue($this->SUT->get('1'));
44+
45+
$this->assertSame('null', $this->SUT->get(''), 'NULL key is typecasted to ""');
46+
$this->assertNull($this->SUT->get('null'), 'No to be confused, this is a normal string');
47+
4248
$this->assertSame('bar', $this->SUT->foo);
4349
$this->assertSame(0, $this->SUT->get('0'));
4450
$this->assertSame(0, $this->SUT->{0});

0 commit comments

Comments
 (0)