getString(), $limit)); } /** * Join array elements with a string * * @param array $pieces The array of strings to join. * @param string $glue Defaults to an empty string. * @param string|null $encoding the desired encoding * * @return Text * Returns a string containing a string representation of all the array elements in the * same order, with the glue string between each element. * * @psalm-suppress MixedArgumentTypeCoercion */ public static function join(array $pieces, string $glue = '', ?string $encoding = null): Text { array_map( function (mixed $element): void { if (!($element === null || is_scalar($element) || $element instanceof \Stringable)) { throw new \TypeError('Can join elements only if scalar, null or \\Stringable'); } }, $pieces ); return new Text(implode($glue, $pieces), $encoding); } /** * Convert the string to an array * * @param int $splitLength Maximum length of the chunk. * * @throws InvalidArgumentException If splitLength is less than 1. * * @return ArrayObject * If the optional splitLength parameter is specified, the returned array will be * broken down into chunks with each being splitLength in length, otherwise each chunk * will be one character in length. * If the split_length length exceeds the length of string, the entire string is returned * as the first (and only) array element. */ public function chunk(int $splitLength = 1): ArrayObject { if (false === $array = str_split($this->getString(), $splitLength)) { throw new InvalidArgumentException('The chunk length has to be positive'); } return new ArrayObject($array); } }