Skip to content

Commit ad047c9

Browse files
committed
fix(analytics): add readonly array access to analytics rules
1 parent 26e6f80 commit ad047c9

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

src/AnalyticsRules.php

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ class AnalyticsRules implements \ArrayAccess
88

99
private ApiCall $apiCall;
1010

11+
/**
12+
* @var array
13+
*/
14+
private array $analyticsRules = [];
15+
1116
public function __construct(ApiCall $apiCall)
1217
{
1318
$this->apiCall = $apiCall;
@@ -42,29 +47,49 @@ public function retrieve()
4247
*/
4348
public function __get($ruleName)
4449
{
45-
return new AnalyticsRule($ruleName, $this->apiCall);
50+
if (isset($this->{$ruleName})) {
51+
return $this->{$ruleName};
52+
}
53+
if (!isset($this->analyticsRules[$ruleName])) {
54+
$this->analyticsRules[$ruleName] = new AnalyticsRule($ruleName, $this->apiCall);
55+
}
56+
57+
return $this->analyticsRules[$ruleName];
4658
}
4759

4860
/**
4961
* ArrayAccess implementation for backwards compatibility
5062
*/
5163
public function offsetExists($offset): bool
5264
{
53-
return true; // Rules can be accessed by name
65+
return isset($this->analyticsRules[$offset]);
5466
}
5567

68+
/**
69+
* @inheritDoc
70+
*/
5671
public function offsetGet($offset): AnalyticsRule
5772
{
58-
return new AnalyticsRule($offset, $this->apiCall);
73+
if (!isset($this->analyticsRules[$offset])) {
74+
$this->analyticsRules[$offset] = new AnalyticsRule($offset, $this->apiCall);
75+
}
76+
77+
return $this->analyticsRules[$offset];
5978
}
6079

80+
/**
81+
* @inheritDoc
82+
*/
6183
public function offsetSet($offset, $value): void
6284
{
63-
// Not implemented for read-only access
85+
$this->analyticsRules[$offset] = $value;
6486
}
6587

88+
/**
89+
* @inheritDoc
90+
*/
6691
public function offsetUnset($offset): void
6792
{
68-
// Not implemented for read-only access
93+
unset($this->analyticsRules[$offset]);
6994
}
7095
}

0 commit comments

Comments
 (0)