Skip to content

Commit dbaf667

Browse files
committed
Make keyToPathArray() a static method
1 parent 5d58a26 commit dbaf667

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/Data.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function __construct(array $data = [])
4747
public function append(string $key, $value = null): void
4848
{
4949
$currentValue =& $this->data;
50-
$keyPath = $this->keyToPathArray($key);
50+
$keyPath = self::keyToPathArray($key);
5151

5252
$endKey = array_pop($keyPath);
5353
foreach ($keyPath as $currentKey) {
@@ -76,7 +76,7 @@ public function append(string $key, $value = null): void
7676
public function set(string $key, $value = null): void
7777
{
7878
$currentValue =& $this->data;
79-
$keyPath = $this->keyToPathArray($key);
79+
$keyPath = self::keyToPathArray($key);
8080

8181
$endKey = array_pop($keyPath);
8282
foreach ($keyPath as $currentKey) {
@@ -97,7 +97,7 @@ public function set(string $key, $value = null): void
9797
public function remove(string $key): void
9898
{
9999
$currentValue =& $this->data;
100-
$keyPath = $this->keyToPathArray($key);
100+
$keyPath = self::keyToPathArray($key);
101101

102102
$endKey = array_pop($keyPath);
103103
foreach ($keyPath as $currentKey) {
@@ -117,7 +117,7 @@ public function remove(string $key): void
117117
public function get(string $key, $default = null)
118118
{
119119
$currentValue = $this->data;
120-
$keyPath = $this->keyToPathArray($key);
120+
$keyPath = self::keyToPathArray($key);
121121

122122
foreach ($keyPath as $currentKey) {
123123
if (!isset($currentValue[$currentKey])) {
@@ -141,7 +141,7 @@ public function has(string $key): bool
141141
{
142142
$currentValue = &$this->data;
143143

144-
foreach ($this->keyToPathArray($key) as $currentKey) {
144+
foreach (self::keyToPathArray($key) as $currentKey) {
145145
if (
146146
!is_array($currentValue) ||
147147
!array_key_exists($currentKey, $currentValue)
@@ -230,13 +230,15 @@ public function offsetUnset($key)
230230
}
231231

232232
/**
233+
* @param string $path
234+
*
233235
* @return string[]
234236
*
235237
* @psalm-return non-empty-list<string>
236238
*
237239
* @psalm-pure
238240
*/
239-
protected function keyToPathArray(string $path): array
241+
protected static function keyToPathArray(string $path): array
240242
{
241243
if (\strlen($path) === 0) {
242244
throw new InvalidPathException('Path cannot be an empty string');

0 commit comments

Comments
 (0)