Issues (100)

src/Impl/Util/StringUtil.php (1 issue)

Severity
1
<?php
2
3
namespace Xml\Impl\Util;
4
5
class StringUtil
6
{
7
    public const PATTERN = '/(\w[^,]*)|([#$]\{[^}]*\})/mu';
8
9
    public static function splitCommaSeparatedList(?string $text): array
10
    {
11
        if (empty($text)) {
12
            return [];
13
        }
14
        preg_match_all(self::PATTERN, $text, $matches);
15
        $parts = [];
16
        foreach ($matches[0] as $match) {
17
            $parts[] = trim($match);
18
        }
19
        return $parts;
20
    }
21
22
    public static function joinCommaSeparatedList(?array $list): ?string
23
    {
24
        return self::joinList($list, ", ");
25
    }
26
27
    public static function splitListBySeparator(?string $text, string $separator): array
28
    {
29
        if (!empty($text)) {
30
            return explode($separator, $text);
31
        }
32
        return [];
33
    }
34
35
    public static function joinList(?array $list, string $separator): ?string
36
    {
37
        return $list === null ? null : implode($separator, $list);
0 ignored issues
show
The condition $list === null is always false.
Loading history...
38
    }
39
}
40