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

orchestral / sidekick / 14616827228

23 Apr 2025 11:18AM UTC coverage: 94.34% (-1.7%) from 96.078%
14616827228

Pull #22

github

web-flow
Merge 960c81414 into b8648fd54
Pull Request #22: `Orchestra\Sidekick\FluentDecorator::__get()` should utilise `Illuminate\Support\Fluent::value()` if the method exists.

1 of 2 new or added lines in 1 file covered. (50.0%)

50 of 53 relevant lines covered (94.34%)

2.21 hits per line

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

93.33
/src/FluentDecorator.php
1
<?php
2

3
namespace Orchestra\Sidekick;
4

5
use ArrayAccess;
6
use Illuminate\Contracts\Support\Arrayable;
7
use Illuminate\Contracts\Support\Jsonable;
8
use Illuminate\Support\Fluent;
9
use Illuminate\Support\Traits\ForwardsCalls;
10
use JsonSerializable;
11

12
/**
13
 * @api
14
 *
15
 * @template TKey of array-key
16
 * @template TValue
17
 *
18
 * @implements \Illuminate\Contracts\Support\Arrayable<TKey, TValue>
19
 * @implements \ArrayAccess<TKey, TValue>
20
 */
21
abstract class FluentDecorator implements Arrayable, ArrayAccess, Jsonable, JsonSerializable
22
{
23
    use ForwardsCalls;
24

25
    /**
26
     * The Fluent instance.
27
     *
28
     * @var \Illuminate\Support\Fluent<TKey, TValue>
29
     */
30
    protected Fluent $fluent;
31

32
    /**
33
     * Create a new fluent instance.
34
     *
35
     * @param  iterable<TKey, TValue>  $attributes
36
     */
37
    public function __construct($attributes = [])
38
    {
39
        $this->fluent = new Fluent($attributes);
4✔
40
    }
41

42
    /**
43
     * Convert the fluent instance to an array.
44
     *
45
     * @return array<TKey, TValue>
46
     */
47
    public function toArray()
48
    {
49
        return $this->fluent->getAttributes();
1✔
50
    }
51

52
    /**
53
     * Convert the object into something JSON serializable.
54
     *
55
     * @return array<TKey, TValue>
56
     */
57
    public function jsonSerialize(): array
58
    {
59
        return $this->toArray();
1✔
60
    }
61

62
    /**
63
     * Convert the fluent instance to JSON.
64
     *
65
     * @param  int  $options
66
     * @return string
67
     */
68
    public function toJson($options = 0)
69
    {
70
        return (string) json_encode($this->jsonSerialize(), $options);
1✔
71
    }
72

73
    /**
74
     * Determine if the given offset exists.
75
     *
76
     * @param  TKey  $offset
77
     */
78
    public function offsetExists($offset): bool
79
    {
80
        return $this->fluent->offsetExists($offset);
3✔
81
    }
82

83
    /**
84
     * Get the value for a given offset.
85
     *
86
     * @param  TKey  $offset
87
     * @return TValue|null
88
     */
89
    public function offsetGet($offset): mixed
90
    {
91
        return $this->fluent->offsetGet($offset);
3✔
92
    }
93

94
    /**
95
     * Set the value at the given offset.
96
     *
97
     * @param  TKey  $offset
98
     * @param  TValue  $value
99
     */
100
    public function offsetSet($offset, $value): void
101
    {
102
        $this->fluent->offsetSet($offset, $value);
1✔
103
    }
104

105
    /**
106
     * Unset the value at the given offset.
107
     *
108
     * @param  TKey  $offset
109
     */
110
    public function offsetUnset($offset): void
111
    {
112
        $this->fluent->offsetUnset($offset);
1✔
113
    }
114

115
    /**
116
     * Handle dynamic calls to the fluent instance to set attributes.
117
     *
118
     * @param  TKey  $method
119
     * @param  array{0: ?TValue}  $parameters
120
     * @return $this
121
     */
122
    public function __call($method, $parameters)
123
    {
124
        return $this->forwardDecoratedCallTo($this->fluent, $method, $parameters);
2✔
125
    }
126

127
    /**
128
     * Dynamically retrieve the value of an attribute.
129
     *
130
     * @param  TKey  $key
131
     * @return TValue|null
132
     */
133
    public function __get($key)
134
    {
135
        if (method_exists($this->fluent, 'value')) {
1✔
NEW
136
            return $this->fluent->value($key);
×
137
        }
138

139
        return $this->fluent->get($key);
1✔
140
    }
141

142
    /**
143
     * Dynamically set the value of an attribute.
144
     *
145
     * @param  TKey  $key
146
     * @param  TValue  $value
147
     * @return void
148
     */
149
    public function __set($key, $value)
150
    {
151
        $this->fluent->offsetSet($key, $value);
1✔
152
    }
153

154
    /**
155
     * Dynamically check if an attribute is set.
156
     *
157
     * @param  TKey  $key
158
     * @return bool
159
     */
160
    public function __isset($key)
161
    {
162
        return $this->fluent->offsetExists($key);
1✔
163
    }
164

165
    /**
166
     * Dynamically unset an attribute.
167
     *
168
     * @param  TKey  $key
169
     * @return void
170
     */
171
    public function __unset($key)
172
    {
173
        $this->fluent->offsetUnset($key);
1✔
174
    }
175
}
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