• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

dragomano / scss-php / 23675604391

28 Mar 2026 02:28AM UTC coverage: 92.642% (+8.1%) from 84.536%
23675604391

push

github

dragomano
Update README

11357 of 12259 relevant lines covered (92.64%)

87.82 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.53
/src/Values/SassList.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Bugo\SCSS\Values;
6

7
use function count;
8
use function ctype_alnum;
9
use function str_contains;
10
use function str_ends_with;
11
use function str_starts_with;
12

13
final class SassList extends AbstractSassValue
14
{
15
    /**
16
     * @param list<string> $items
17
     */
18
    public function __construct(
19
        private readonly array $items,
20
        private readonly string $separator = 'space',
21
        private readonly bool $bracketed = false,
22
        private readonly bool $shorthand = true
23
    ) {}
156✔
24

25
    public function toCss(): string
26
    {
27
        $items = $this->filterNullItems($this->items);
156✔
28
        $items = $this->optimizeBoxItems($items);
156✔
29

30
        $value    = '';
156✔
31
        $first    = true;
156✔
32
        $previous = '';
156✔
33

34
        foreach ($items as $formatted) {
156✔
35
            if (! $first) {
156✔
36
                $joiner = $this->resolveSeparator();
154✔
37

38
                if (
39
                    $this->separator === 'space'
154✔
40
                    && (
41
                        (
154✔
42
                            str_ends_with($previous, '-')
154✔
43
                            && $previous !== '-'
154✔
44
                            && $formatted !== ''
154✔
45
                            && (str_starts_with($formatted, '#{') || ctype_alnum($formatted[0]))
154✔
46
                        )
154✔
47
                        || (
154✔
48
                            str_ends_with($previous, '}')
154✔
49
                            && str_contains($previous, '#{')
154✔
50
                            && str_starts_with($formatted, '-')
154✔
51
                        )
154✔
52
                    )
53
                ) {
54
                    $joiner = '';
1✔
55
                }
56

57
                $value .= $joiner;
154✔
58
            }
59

60
            $value .= $formatted;
156✔
61

62
            $first    = false;
156✔
63
            $previous = $formatted;
156✔
64
        }
65

66
        if ($this->bracketed) {
156✔
67
            return '[' . $value . ']';
5✔
68
        }
69

70
        return $value;
152✔
71
    }
72

73
    public function isTruthy(): bool
74
    {
75
        return true;
1✔
76
    }
77

78
    private function resolveSeparator(): string
79
    {
80
        return match ($this->separator) {
154✔
81
            'comma' => ', ',
29✔
82
            'slash' => ' / ',
6✔
83
            default => ' ',
154✔
84
        };
154✔
85
    }
86

87
    /**
88
     * @param list<string> $items
89
     * @return list<string>
90
     */
91
    private function optimizeBoxItems(array $items): array
92
    {
93
        $count = count($items);
156✔
94

95
        if (! $this->shorthand || $this->separator !== 'space' || $this->bracketed || $count < 2 || $count > 4) {
156✔
96
            return $items;
99✔
97
        }
98

99
        if ($count === 4) {
66✔
100
            $a = $items[0];
15✔
101
            $b = $items[1];
15✔
102
            $c = $items[2];
15✔
103
            $d = $items[3];
15✔
104

105
            if ($a === $b && $b === $c && $c === $d) {
15✔
106
                return [$a];
2✔
107
            }
108

109
            if ($a === $c && $b === $d) {
15✔
110
                return [$a, $b];
3✔
111
            }
112

113
            if ($b === $d) {
12✔
114
                return [$a, $b, $c];
1✔
115
            }
116

117
            return $items;
11✔
118
        }
119

120
        if ($count === 3) {
58✔
121
            $a = $items[0];
42✔
122
            $b = $items[1];
42✔
123
            $c = $items[2];
42✔
124

125
            if ($a === $b && $b === $c) {
42✔
126
                return [$a];
3✔
127
            }
128

129
            if ($a === $c) {
41✔
130
                return [$a, $b];
3✔
131
            }
132

133
            return $items;
38✔
134
        }
135

136
        if ($items[0] === $items[1]) {
24✔
137
            return [$items[0]];
3✔
138
        }
139

140
        return $items;
23✔
141
    }
142

143
    /**
144
     * @param list<string> $items
145
     * @return list<string>
146
     */
147
    private function filterNullItems(array $items): array
148
    {
149
        $filtered = [];
156✔
150

151
        foreach ($items as $item) {
156✔
152
            if ($item === 'null') {
156✔
153
                continue;
×
154
            }
155

156
            $filtered[] = $item;
156✔
157
        }
158

159
        return $filtered;
156✔
160
    }
161
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc