Chris@0: getName() == 'ArrayObject')) { Chris@0: return 'an array'; Chris@0: } Chris@0: return 'an instance of ' . $data->getName(); Chris@0: } Chris@0: if (is_string($data)) { Chris@0: return 'a string'; Chris@0: } Chris@0: if (is_object($data)) { Chris@0: return 'an instance of ' . get_class($data); Chris@0: } Chris@0: throw new \Exception("Undescribable data error: " . var_export($data, true)); Chris@0: } Chris@0: Chris@0: protected static function describeAllowedTypes($allowedTypes) Chris@0: { Chris@0: if (is_array($allowedTypes) && !empty($allowedTypes)) { Chris@0: if (count($allowedTypes) > 1) { Chris@0: return static::describeListOfAllowedTypes($allowedTypes); Chris@0: } Chris@0: $allowedTypes = $allowedTypes[0]; Chris@0: } Chris@0: return static::describeDataType($allowedTypes); Chris@0: } Chris@0: Chris@0: protected static function describeListOfAllowedTypes($allowedTypes) Chris@0: { Chris@0: $descriptions = []; Chris@0: foreach ($allowedTypes as $oneAllowedType) { Chris@0: $descriptions[] = static::describeDataType($oneAllowedType); Chris@0: } Chris@0: if (count($descriptions) == 2) { Chris@0: return "either {$descriptions[0]} or {$descriptions[1]}"; Chris@0: } Chris@0: $lastDescription = array_pop($descriptions); Chris@0: $otherDescriptions = implode(', ', $descriptions); Chris@0: return "one of $otherDescriptions or $lastDescription"; Chris@0: } Chris@0: }