protected function validateItem($item, $target)
{
$type = gettype($item);
$shouldBeCallable = $target === 'callable';
$isObject = $type === "object";
$looseObjectCheck = $target === "object";
//callable must be callable
if ($shouldBeCallable && !is_callable($item)) {
throw new InvalidArgumentException("Item must be callable");
}
//target isn't callable, object must be an instance of target
if (!$shouldBeCallable && $isObject && !is_a($item, $target) && !$looseObjectCheck) {
throw new InvalidArgumentException("Item is not type or subtype of " . $target);
}
//a non callable, non object type should match the target string
if (!$shouldBeCallable && !$isObject && $type != $target) {
throw new InvalidArgumentException("Item is not of type: " . $target);
}
}