Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not wrap exception message in array #141

Merged
merged 1 commit into from
Mar 15, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/StaticAddToTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ trait StaticAddToTrait
public static function addTo(object $parent, $seed = [], array $add_args = [])
{
if (func_num_args() > 3) { // prevent bad usage
throw new \Error(['Too many method arguments']);
throw new \Error('Too many method arguments');
}

if (is_object($seed)) {
$object = $seed;
} else {
if (!is_array($seed)) {
if (!is_scalar($seed)) { // allow single element seed but prevent bad usage
throw (new Exception(['Seed must be an array or a scalar']))
throw (new Exception('Seed must be an array or a scalar'))
->addMoreInfo('seed_type', gettype($seed));
}

Expand All @@ -62,7 +62,7 @@ private static function _addTo_add(object $parent, object $object, bool $unsafe,
{
// check if object is instance of this class
if (!$unsafe && !($object instanceof static)) {
throw (new Exception(['Seed class name is not a subtype of the current class']))
throw (new Exception('Seed class name is not a subtype of the current class'))
->addMoreInfo('seed_class', get_class($object))
->addMoreInfo('current_class', static::class);
}
Expand All @@ -83,7 +83,7 @@ private static function _addTo_add(object $parent, object $object, bool $unsafe,
public static function addToWithClassName(object $parent, $seed = [], array $add_args = [])
{
if (func_num_args() > 3) { // prevent bad usage
throw new \Error(['Too many method arguments']);
throw new \Error('Too many method arguments');
}

return static::_addToWithClassName($parent, $seed, false, $add_args);
Expand All @@ -99,7 +99,7 @@ public static function addToWithClassName(object $parent, $seed = [], array $add
public static function addToWithClassNameUnsafe(object $parent, $seed = [], array $add_args = [])
{
if (func_num_args() > 3) { // prevent bad usage
throw new \Error(['Too many method arguments']);
throw new \Error('Too many method arguments');
}

return static::_addToWithClassName($parent, $seed, true, $add_args);
Expand All @@ -115,7 +115,7 @@ private static function _addToWithClassName(object $parent, $seed, bool $unsafe,
} else {
if (!is_array($seed)) {
if (!is_scalar($seed)) { // allow single element seed but prevent bad usage
throw (new Exception(['Seed must be an array or a scalar']))
throw (new Exception('Seed must be an array or a scalar'))
->addMoreInfo('seed_type', gettype($seed));
}

Expand Down