Skip to content

Commit 2e95384

Browse files
committed
function call for variable handling changed
1 parent c47307e commit 2e95384

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

src/TypedArray.php

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ class TypedArray extends ArrayObject
2525
* @var array Types supported by class
2626
*/
2727
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'
3535
];
3636

3737
/**
@@ -40,7 +40,9 @@ class TypedArray extends ArrayObject
4040
protected $type = '';
4141

4242
/**
43-
* Contructor.
43+
* __construct.
44+
*
45+
* Class Contructor.
4446
*
4547
* @param string $type
4648
* @param array $array
@@ -55,10 +57,10 @@ public function __construct(string $type, array $array = [])
5557
if (!isset($this->allowedTypes[$type])) {
5658
throw new InvalidArgumentException(__CLASS__.': '.$type.' type passed to '.__METHOD__.' not supported.');
5759
}
58-
60+
5961
//for not utilize foreach, compare sizes of array
6062
//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]))) {
6264
throw new InvalidArgumentException(__CLASS__.': Elements passed to '.__METHOD__.' must be of the type '.$type.'.');
6365
}
6466

@@ -70,6 +72,8 @@ public function __construct(string $type, array $array = [])
7072
}
7173

7274
/**
75+
* offsetSet.
76+
*
7377
* Array style value assignment.
7478
*
7579
* @ignore
@@ -83,13 +87,12 @@ public function __construct(string $type, array $array = [])
8387
*/
8488
public function offsetSet($index, $newval)
8589
{
86-
$is_ = 'is_'.$this->type;
87-
88-
if ($is_($newval)) {
90+
if (($this->allowedTypes[$this->type])($newval)) {
8991
parent::offsetSet($index, $newval);
9092

9193
return;
9294
}
95+
9396
throw new InvalidArgumentException(__CLASS__.': Elements passed to '.__CLASS__.' must be of the type '.$this->type.'.');
9497
}
9598
}

src/TypedObjectArray.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ class TypedObjectArray extends ArrayObject
2727
protected $type = '';
2828

2929
/**
30-
* Contructor.
30+
* __construct.
31+
*
32+
* Class Contructor.
3133
*
3234
* @param string $type
3335
* @param array $array
@@ -57,6 +59,8 @@ public function __construct(string $type, array $array = [])
5759
}
5860

5961
/**
62+
* offsetSet.
63+
*
6064
* Array style value assignment.
6165
*
6266
* @ignore

0 commit comments

Comments
 (0)