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

conedevelopment / root / 15084089635

17 May 2025 10:00AM UTC coverage: 77.93% (+0.04%) from 77.891%
15084089635

push

github

web-flow
Modernize back-end.yml (#240)

3291 of 4223 relevant lines covered (77.93%)

36.04 hits per line

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

50.0
/src/Support/ClassList.php
1
<?php
2

3
namespace Cone\Root\Support;
4

5
use Illuminate\Contracts\Support\Arrayable;
6
use Illuminate\Support\Arr;
7
use Stringable;
8

9
class ClassList implements Arrayable, Stringable
10
{
11
    /**
12
     * The class list items.
13
     */
14
    protected array $classes = [];
15

16
    /**
17
     * Create a new class list instance.
18
     */
19
    public function __construct(array $classes = [])
198✔
20
    {
21
        $this->classes = $classes;
198✔
22
    }
23

24
    /**
25
     * Add new classes to the class list.
26
     */
27
    public function add(string|array $value): static
198✔
28
    {
29
        $value = is_array($value) ? $value : explode(' ', $value);
198✔
30

31
        $this->classes = array_values(array_unique(
198✔
32
            array_merge($this->classes, $value)
198✔
33
        ));
198✔
34

35
        return $this;
198✔
36
    }
37

38
    /**
39
     * Remove classes from the class list.
40
     */
41
    public function remove(string|array $value): static
×
42
    {
43
        $this->classes = array_values(
×
44
            array_diff($this->classes, (array) $value)
×
45
        );
×
46

47
        return $this;
×
48
    }
49

50
    /**
51
     * Replace the given values in the class list.
52
     */
53
    public function replace(string $old, string $new): static
3✔
54
    {
55
        $index = array_search($old, $this->classes);
3✔
56

57
        if ($index !== false) {
3✔
58
            $this->classes[$index] = $new;
3✔
59
        }
60

61
        return $this;
3✔
62
    }
63

64
    /**
65
     * Toggle a class in the class list.
66
     */
67
    public function toggle(string $value, ?bool $force = null): static
×
68
    {
69
        if (is_null($force)) {
×
70
            $this->contains($value) ? $this->remove($value) : $this->add($value);
×
71
        } elseif ($force) {
×
72
            $this->add($value);
×
73
        } else {
74
            $this->remove($value);
×
75
        }
76

77
        return $this;
×
78
    }
79

80
    /**
81
     * Determine whether the class is present in the class list.
82
     */
83
    public function contains(string $value): bool
×
84
    {
85
        return in_array($value, $this->classes);
×
86
    }
87

88
    /**
89
     * Clear the class list.
90
     */
91
    public function clear(): static
×
92
    {
93
        $this->classes = [];
×
94

95
        return $this;
×
96
    }
97

98
    /**
99
     * Convert the class list to an array.
100
     */
101
    public function toArray(): array
14✔
102
    {
103
        return array_values(array_unique($this->classes));
14✔
104
    }
105

106
    /**
107
     * Convert the class list to a string.
108
     */
109
    public function __toString(): string
14✔
110
    {
111
        return Arr::toCssClasses($this->toArray());
14✔
112
    }
113
}
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

© 2025 Coveralls, Inc