Skip to content

Commit b49c490

Browse files
authored
Merge pull request #3 from s3b4stian/s3b4stian-patch-1
InvalidArgumentException instead fo TypeError
2 parents 69da612 + e97f187 commit b49c490

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/TypedArray.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
use ArrayObject;
1515
use InvalidArgumentException;
16-
use TypeError;
1716

1817
/**
1918
* Create an array of typed elements.
@@ -44,22 +43,21 @@ class TypedArray extends ArrayObject
4443
* @param string $type
4544
* @param array $array
4645
*
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
4948
* are not of the configured type
5049
*/
5150
public function __construct(string $type, array $array = [])
5251
{
5352
//single class, multi type support :)
54-
//if (!isset($this->allowedTypes[$type])){
5553
if (!in_array($type, $this->allowedTypes)) {
5654
throw new InvalidArgumentException($type.' type passed to '.__CLASS__.' not supported');
5755
}
5856

5957
//for not utilize foreach, compare sizes of array
6058
//before and after apply a filter :)
6159
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);
6361
}
6462

6563
//call parent constructor
@@ -75,7 +73,7 @@ public function __construct(string $type, array $array = [])
7573
* @param mixed $index
7674
* @param mixed $newval
7775
*
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
7977
*
8078
* @return void
8179
*/
@@ -88,6 +86,6 @@ public function offsetSet($index, $newval)
8886

8987
return;
9088
}
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);
9290
}
9391
}

0 commit comments

Comments
 (0)