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

orchestral / sidekick / 14617240769

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

push

github

web-flow
`Orchestra\Sidekick\FluentDecorator::__get()` should utilise `Illuminate\Support\Fluent::value()` if the method exists. (#22)

* `FluentDecorator::__get()` should utilise `Fluent::value()` if the
method exists.

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>

* wip

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>

* wip

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>

* wip

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>

---------

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>

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
        /** @phpstan-ignore function.alreadyNarrowedType */
136
        if (method_exists($this->fluent, 'value')) {
1✔
NEW
137
            return $this->fluent->value($key);
×
138
        }
139

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

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

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

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