1111
1212namespace Dflydev \DotAccessData ;
1313
14+ use RuntimeException ;
15+
1416class Data implements DataInterface
1517{
1618 /**
@@ -27,7 +29,7 @@ class Data implements DataInterface
2729 */
2830 public function __construct (array $ data = null )
2931 {
30- $ this ->data = $ data ?: array () ;
32+ $ this ->data = $ data ?: [] ;
3133 }
3234
3335 /**
@@ -36,20 +38,20 @@ public function __construct(array $data = null)
3638 public function append ($ key , $ value = null )
3739 {
3840 if (0 == strlen ($ key )) {
39- throw new \ RuntimeException ("Key cannot be an empty string " );
41+ throw new RuntimeException ("Key cannot be an empty string " );
4042 }
4143
4244 $ currentValue =& $ this ->data ;
4345 $ keyPath = explode ('. ' , $ key );
4446
4547 if (1 == count ($ keyPath )) {
4648 if (!isset ($ currentValue [$ key ])) {
47- $ currentValue [$ key ] = array () ;
49+ $ currentValue [$ key ] = [] ;
4850 }
4951 if (!is_array ($ currentValue [$ key ])) {
5052 // Promote this key to an array.
5153 // TODO: Is this really what we want to do?
52- $ currentValue [$ key ] = array ( $ currentValue [$ key ]) ;
54+ $ currentValue [$ key ] = [ $ currentValue [$ key ]] ;
5355 }
5456 $ currentValue [$ key ][] = $ value ;
5557
@@ -60,16 +62,16 @@ public function append($key, $value = null)
6062 for ( $ i = 0 ; $ i < count ($ keyPath ); $ i ++ ) {
6163 $ currentKey =& $ keyPath [$ i ];
6264 if ( ! isset ($ currentValue [$ currentKey ]) ) {
63- $ currentValue [$ currentKey ] = array () ;
65+ $ currentValue [$ currentKey ] = [] ;
6466 }
6567 $ currentValue =& $ currentValue [$ currentKey ];
6668 }
6769
6870 if (!isset ($ currentValue [$ endKey ])) {
69- $ currentValue [$ endKey ] = array () ;
71+ $ currentValue [$ endKey ] = [] ;
7072 }
7173 if (!is_array ($ currentValue [$ endKey ])) {
72- $ currentValue [$ endKey ] = array ( $ currentValue [$ endKey ]) ;
74+ $ currentValue [$ endKey ] = [ $ currentValue [$ endKey ]] ;
7375 }
7476 // Promote this key to an array.
7577 // TODO: Is this really what we want to do?
@@ -82,7 +84,7 @@ public function append($key, $value = null)
8284 public function set ($ key , $ value = null )
8385 {
8486 if (0 == strlen ($ key )) {
85- throw new \ RuntimeException ("Key cannot be an empty string " );
87+ throw new RuntimeException ("Key cannot be an empty string " );
8688 }
8789
8890 $ currentValue =& $ this ->data ;
@@ -98,10 +100,10 @@ public function set($key, $value = null)
98100 for ( $ i = 0 ; $ i < count ($ keyPath ); $ i ++ ) {
99101 $ currentKey =& $ keyPath [$ i ];
100102 if (!isset ($ currentValue [$ currentKey ])) {
101- $ currentValue [$ currentKey ] = array () ;
103+ $ currentValue [$ currentKey ] = [] ;
102104 }
103105 if (!is_array ($ currentValue [$ currentKey ])) {
104- throw new \ RuntimeException ("Key path at $ currentKey of $ key cannot be indexed into (is not an array) " );
106+ throw new RuntimeException ("Key path at $ currentKey of $ key cannot be indexed into (is not an array) " );
105107 }
106108 $ currentValue =& $ currentValue [$ currentKey ];
107109 }
@@ -114,7 +116,7 @@ public function set($key, $value = null)
114116 public function remove ($ key )
115117 {
116118 if (0 == strlen ($ key )) {
117- throw new \ RuntimeException ("Key cannot be an empty string " );
119+ throw new RuntimeException ("Key cannot be an empty string " );
118120 }
119121
120122 $ currentValue =& $ this ->data ;
@@ -191,7 +193,7 @@ public function getData($key)
191193 return new Data ($ value );
192194 }
193195
194- throw new \ RuntimeException ("Value at ' $ key' could not be represented as a DataInterface " );
196+ throw new RuntimeException ("Value at ' $ key' could not be represented as a DataInterface " );
195197 }
196198
197199 /**
0 commit comments