value) ? "'$value->value'" : (string)$value->value; } if ($value instanceof UnitEnum) { return "'$value->name'"; } if ($value instanceof DateTimeInterface) { return $value->format(self::DATE_FORMAT); } if (is_iterable($value) && ! $value instanceof Generator) { /** @var iterable $value */ if (is_array($value)) { $type = 'array'; } else { $type = 'iterable'; } $values = self::listValues($value); if (empty($values)) { return "$type (empty)"; } if (! $goDeeper) { return "$type{…}"; } return "$type{" . implode(', ', $values) . '}'; } if (is_object($value)) { return 'object(' . $value::class . ')'; } // @codeCoverageIgnoreStart return 'unknown'; // @codeCoverageIgnoreEnd } /** * @param iterable $iterable * @return array */ private static function listValues(iterable $iterable): array { $values = []; $index = 0; foreach ($iterable as $key => $value) { $values[] = "$key: " . self::doDump($value, false); if ($index++ >= self::MAX_ARRAY_ENTRIES) { $values[] = '…'; break; } } return $values; } private static function crop(string $string): string { if (strlen($string) <= self::MAX_STRING_LENGTH) { return $string; } $string = StringCutter::cut($string, self::MAX_STRING_LENGTH + 1); for ($i = strlen($string) - 1; $i > 10; $i--) { if ($string[$i] === ' ') { return StringCutter::cut($string, $i) . '…'; } } return $string . '…'; } }