13
13
14
14
use ArrayObject ;
15
15
use InvalidArgumentException ;
16
- use TypeError ;
17
16
18
17
/**
19
18
* Create an array of typed elements.
@@ -44,22 +43,21 @@ class TypedArray extends ArrayObject
44
43
* @param string $type
45
44
* @param array $array
46
45
*
47
- * @throws InvalidArgumentException If type is not supported
48
- * @throws TypeError If elements of passed with $array
46
+ * @throws InvalidArgumentException If type is not supported and if
47
+ * elements of passed with $array
49
48
* are not of the configured type
50
49
*/
51
50
public function __construct (string $ type , array $ array = [])
52
51
{
53
52
//single class, multi type support :)
54
- //if (!isset($this->allowedTypes[$type])){
55
53
if (!in_array ($ type , $ this ->allowedTypes )) {
56
54
throw new InvalidArgumentException ($ type .' type passed to ' .__CLASS__ .' not supported ' );
57
55
}
58
56
59
57
//for not utilize foreach, compare sizes of array
60
58
//before and after apply a filter :)
61
59
if (count ($ array ) > count (array_filter ($ array , 'is_ ' .$ type ))) {
62
- throw new TypeError ('Elements passed to ' .__CLASS__ .' must be of the type ' .$ type );
60
+ throw new InvalidArgumentException ('Elements passed to ' .__CLASS__ .' must be of the type ' .$ type );
63
61
}
64
62
65
63
//call parent constructor
@@ -75,7 +73,7 @@ public function __construct(string $type, array $array = [])
75
73
* @param mixed $index
76
74
* @param mixed $newval
77
75
*
78
- * @throws TypeError If value passed with $newval are not of the configured type
76
+ * @throws InvalidArgumentException If value passed with $newval are not of the configured type
79
77
*
80
78
* @return void
81
79
*/
@@ -88,6 +86,6 @@ public function offsetSet($index, $newval)
88
86
89
87
return ;
90
88
}
91
- throw new TypeError ('Elements passed to ' .__CLASS__ .' must be of the type ' .$ this ->type );
89
+ throw new InvalidArgumentException ('Elements passed to ' .__CLASS__ .' must be of the type ' .$ this ->type );
92
90
}
93
91
}
0 commit comments