@@ -25,13 +25,13 @@ class TypedArray extends ArrayObject
25
25
* @var array Types supported by class
26
26
*/
27
27
protected $ allowedTypes = [
28
- 'array ' => 1 ,
29
- 'bool ' => 1 ,
30
- 'callable ' => 1 ,
31
- 'float ' => 1 ,
32
- 'int ' => 1 ,
33
- 'object ' => 1 ,
34
- 'string ' => 1
28
+ 'array ' => ' is_array ' ,
29
+ 'bool ' => ' is_bool ' ,
30
+ 'callable ' => ' is_callable ' ,
31
+ 'float ' => ' is_float ' ,
32
+ 'int ' => ' is_int ' ,
33
+ 'object ' => ' is_object ' ,
34
+ 'string ' => ' is_string '
35
35
];
36
36
37
37
/**
@@ -40,7 +40,9 @@ class TypedArray extends ArrayObject
40
40
protected $ type = '' ;
41
41
42
42
/**
43
- * Contructor.
43
+ * __construct.
44
+ *
45
+ * Class Contructor.
44
46
*
45
47
* @param string $type
46
48
* @param array $array
@@ -55,10 +57,10 @@ public function __construct(string $type, array $array = [])
55
57
if (!isset ($ this ->allowedTypes [$ type ])) {
56
58
throw new InvalidArgumentException (__CLASS__ .': ' .$ type .' type passed to ' .__METHOD__ .' not supported. ' );
57
59
}
58
-
60
+
59
61
//for not utilize foreach, compare sizes of array
60
62
//before and after apply a filter :)
61
- if (count ($ array ) > count (array_filter ($ array , ' is_ ' . $ type ))) {
63
+ if (count ($ array ) > count (array_filter ($ array , $ this -> allowedTypes [ $ type] ))) {
62
64
throw new InvalidArgumentException (__CLASS__ .': Elements passed to ' .__METHOD__ .' must be of the type ' .$ type .'. ' );
63
65
}
64
66
@@ -70,6 +72,8 @@ public function __construct(string $type, array $array = [])
70
72
}
71
73
72
74
/**
75
+ * offsetSet.
76
+ *
73
77
* Array style value assignment.
74
78
*
75
79
* @ignore
@@ -83,13 +87,12 @@ public function __construct(string $type, array $array = [])
83
87
*/
84
88
public function offsetSet ($ index , $ newval )
85
89
{
86
- $ is_ = 'is_ ' .$ this ->type ;
87
-
88
- if ($ is_ ($ newval )) {
90
+ if (($ this ->allowedTypes [$ this ->type ])($ newval )) {
89
91
parent ::offsetSet ($ index , $ newval );
90
92
91
93
return ;
92
94
}
95
+
93
96
throw new InvalidArgumentException (__CLASS__ .': Elements passed to ' .__CLASS__ .' must be of the type ' .$ this ->type .'. ' );
94
97
}
95
98
}
0 commit comments