Skip to content

Commit 12013e1

Browse files
authored
Merge pull request #10 from linna/exception-update
Exception messages updated
2 parents 443ca70 + f388335 commit 12013e1

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

CHANGELOG.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
88

99
## [Unrelased ][v1.0.3](https://github.com/linna/typed-array/compare/v1.0.1...v1.0.3) - 2017-XX-XX
1010

11+
### Changed
12+
* `Linna\TypedArray` exception messages updated
13+
* `Linna\TypedObjectArray` exception messages updated
14+
1115
### Fixed
1216
* `CHANGELOG.md` links url
1317

@@ -24,5 +28,5 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2428
## [v1.0.0](https://github.com/linna/typed-array/compare/v1.0.0...master) - 2017-06-07
2529

2630
### Added
27-
* `Linna\TypedArray` for create arrays that accept only values of the user defined type.
28-
* `Linna\TypedObjectArray` for create arrays that accept only class instances of the user defined type.
31+
* `Linna\TypedArray` for create arrays that accept only values of the user defined type
32+
* `Linna\TypedObjectArray` for create arrays that accept only class instances of the user defined type

src/TypedArray.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ public function __construct(string $type, array $array = [])
5151
{
5252
//single class, multi type support :)
5353
if (!isset($this->allowedTypes[$type])) {
54-
throw new InvalidArgumentException($type.' type passed to '.__CLASS__.' not supported');
54+
throw new InvalidArgumentException(__CLASS__.': '.$type.' type passed to '.__METHOD__.' not supported.');
5555
}
5656

5757
//for not utilize foreach, compare sizes of array
5858
//before and after apply a filter :)
5959
if (count($array) > count(array_filter($array, 'is_'.$type))) {
60-
throw new InvalidArgumentException('Elements passed to '.__CLASS__.' must be of the type '.$type);
60+
throw new InvalidArgumentException(__CLASS__.': Elements passed to '.__METHOD__.' must be of the type '.$type.'.');
6161
}
6262

6363
//call parent constructor
@@ -86,6 +86,6 @@ public function offsetSet($index, $newval)
8686

8787
return;
8888
}
89-
throw new InvalidArgumentException('Elements passed to '.__CLASS__.' must be of the type '.$this->type);
89+
throw new InvalidArgumentException(__CLASS__.': Elements passed to '.__CLASS__.' must be of the type '.$this->type.'.');
9090
}
9191
}

src/TypedObjectArray.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class TypedObjectArray extends ArrayObject
3636
public function __construct(string $type, array $array = [])
3737
{
3838
if (!class_exists($type)) {
39-
throw new InvalidArgumentException('Type passed to '.__CLASS__.' must be an existing class');
39+
throw new InvalidArgumentException(__CLASS__.': Type passed to '.__METHOD__.' must be an existing class');
4040
}
4141

4242
//check elements of passed array
@@ -45,7 +45,7 @@ public function __construct(string $type, array $array = [])
4545
if ($element instanceof $type) {
4646
continue;
4747
}
48-
throw new InvalidArgumentException('Elements passed to '.__CLASS__.' must be of the type '.$type);
48+
throw new InvalidArgumentException(__CLASS__.': Elements passed to '.__METHOD__.' must be of the type '.$type.'.');
4949
}
5050

5151
//call parent constructor
@@ -71,6 +71,6 @@ public function offsetSet($index, $newval)
7171

7272
return;
7373
}
74-
throw new InvalidArgumentException('Elements passed to '.__CLASS__.' must be of the type '.$this->type);
74+
throw new InvalidArgumentException(__CLASS__.': Elements passed to '.__CLASS__.' must be of the type '.$this->type.'.');
7575
}
7676
}

0 commit comments

Comments
 (0)