Skip to content

Commit 637b502

Browse files
committed
fix
1 parent 45c6595 commit 637b502

File tree

2 files changed

+27
-21
lines changed

2 files changed

+27
-21
lines changed

src/Traits/ArrayStorage.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ trait ArrayStorage
1515
/** @var array */
1616
private $data = [];
1717

18-
private function propertyExists($name): bool
18+
/**
19+
* @param string $name
20+
*
21+
* @return bool
22+
*/
23+
private function propertyExists(string $name): bool
1924
{
2025
return $name !== 'data' && property_exists($this, $name);
2126
}
@@ -31,16 +36,13 @@ public function __get(string $name)
3136
return $this->$name;
3237
}
3338

34-
if (array_key_exists($name, $this->data)) {
35-
$val = Arr::get($this->data, $name);
36-
return $this->data[$name];
39+
if (Arr::has($this->data, $name)) {
40+
return Arr::get($this->data, $name);
3741
}
3842

3943
$trace = debug_backtrace();
4044
trigger_error(
41-
'Undefined property in __get(): ' . $name .
42-
' in file ' . $trace[0]['file'] .
43-
' in line ' . $trace[0]['line'],
45+
"Undefined property in __get(): $name in file {$trace[0]['file']} in line {$trace[0]['line']}",
4446
E_USER_NOTICE);
4547
return null;
4648
}
@@ -55,7 +57,7 @@ public function __set(string $name, $value): void
5557
$this->$name = $value;
5658
}
5759

58-
$this->data[$name] = $value;
60+
Arr::set($this->data, $name, $value);
5961
}
6062

6163
/**

tests/traits/ArrayStorageTest.php

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,26 @@ public function testDeepData(): void
4040
static::assertEquals('test', $config->{'upper.sad.as'});
4141
}
4242

43-
public function testUnset(): void
43+
public function testGetData(): void
4444
{
4545
$config = new ArrayStorageClassTest;
46-
$key = 'test.sub.key';
47-
48-
static::assertFalse(isset($config->$key));
49-
50-
$config->$key = 1;
51-
static::assertTrue(isset($config->$key));
52-
53-
static::assertEquals(1, $config->$key);
54-
55-
unset($config->$key);
56-
57-
static::assertFalse(isset($config->$key));
5846

47+
$config->{'test.sub.key'} = 1;
48+
$config->{'test.sub.val'} = 'value';
49+
50+
$config->{'test.next'} = 'next value';
51+
$expected = [
52+
'test' => [
53+
'sub' => [
54+
'key' => 1,
55+
'val' => 'value',
56+
],
57+
'next' => 'next value',
58+
],
59+
];
60+
61+
static::assertEquals($expected['test'], $config->test);
62+
static::assertEquals($expected, $config->getData());
5963
}
6064

6165
public function testUnset2(): void

0 commit comments

Comments
 (0)