Skip to content

Commit 483bc4e

Browse files
jasonvargaclaude
andcommitted
Simplify getQueryableValue allowlist check
Remove redundant method_exists check since the allowlist already contains only known methods. Rename methodIsSafeToQuery to queryableMethods, returning the array directly. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent ca126b4 commit 483bc4e

4 files changed

Lines changed: 16 additions & 16 deletions

File tree

src/Assets/Asset.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,7 +1116,7 @@ public function hasDuration()
11161116

11171117
public function getQueryableValue(string $field)
11181118
{
1119-
if (method_exists($this, $method = Str::camel($field)) && $this->methodIsSafeToQuery($method)) {
1119+
if (in_array($method = Str::camel($field), $this->queryableMethods())) {
11201120
return $this->{$method}();
11211121
}
11221122

@@ -1129,15 +1129,15 @@ public function getQueryableValue(string $field)
11291129
return $field->fieldtype()->toQueryableValue($value);
11301130
}
11311131

1132-
private function methodIsSafeToQuery(string $method): bool
1132+
private function queryableMethods(): array
11331133
{
1134-
return in_array($method, [
1134+
return [
11351135
'id', 'path', 'folder', 'filename', 'basename', 'extension',
11361136
'blueprint', 'container', 'containerId', 'containerHandle',
11371137
'size', 'lastModified', 'mimeType',
11381138
'width', 'height', 'orientation', 'ratio', 'duration',
11391139
'isImage', 'isVideo', 'isAudio', 'isSvg', 'isMedia', 'isPdf',
1140-
]);
1140+
];
11411141
}
11421142

11431143
public function getCurrentDirtyStateAttributes(): array

src/Auth/User.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ protected function getComputedCallbacks()
365365

366366
public function getQueryableValue(string $field)
367367
{
368-
if (method_exists($this, $method = Str::camel($field)) && $this->methodIsSafeToQuery($method)) {
368+
if (in_array($method = Str::camel($field), $this->queryableMethods())) {
369369
return $this->{$method}();
370370
}
371371

@@ -378,12 +378,12 @@ public function getQueryableValue(string $field)
378378
return $field->fieldtype()->toQueryableValue($value);
379379
}
380380

381-
private function methodIsSafeToQuery(string $method): bool
381+
private function queryableMethods(): array
382382
{
383-
return in_array($method, [
383+
return [
384384
'id', 'path', 'email', 'name', 'blueprint',
385385
'roles', 'groups', 'isSuper',
386386
'lastLogin', 'preferredLocale',
387-
]);
387+
];
388388
}
389389
}

src/Entries/Entry.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,7 +1098,7 @@ public function getQueryableValue(string $field)
10981098
Blink::store('entry-uris')->forget($this->id());
10991099
}
11001100

1101-
if (method_exists($this, $method = Str::camel($field)) && $this->methodIsSafeToQuery($method)) {
1101+
if (in_array($method = Str::camel($field), $this->queryableMethods())) {
11021102
return $this->{$method}();
11031103
}
11041104

@@ -1111,13 +1111,13 @@ public function getQueryableValue(string $field)
11111111
return $field->fieldtype()->toQueryableValue($value);
11121112
}
11131113

1114-
private function methodIsSafeToQuery(string $method): bool
1114+
private function queryableMethods(): array
11151115
{
1116-
return in_array($method, [
1116+
return [
11171117
'id', 'path', 'slug', 'uri', 'status', 'published',
11181118
'date', 'order', 'collection', 'collectionHandle',
11191119
'blueprint', 'locale', 'site', 'lastModified',
1120-
]);
1120+
];
11211121
}
11221122

11231123
public function getSearchValue(string $field)

src/Taxonomies/LocalizedTerm.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ public function repository()
485485

486486
public function getQueryableValue(string $field)
487487
{
488-
if (method_exists($this, $method = Str::camel($field)) && $this->methodIsSafeToQuery($method)) {
488+
if (in_array($method = Str::camel($field), $this->queryableMethods())) {
489489
return $this->{$method}();
490490
}
491491

@@ -498,13 +498,13 @@ public function getQueryableValue(string $field)
498498
return $field->fieldtype()->toQueryableValue($value);
499499
}
500500

501-
private function methodIsSafeToQuery(string $method): bool
501+
private function queryableMethods(): array
502502
{
503-
return in_array($method, [
503+
return [
504504
'id', 'path', 'slug', 'title', 'uri',
505505
'taxonomy', 'taxonomyHandle', 'blueprint',
506506
'locale', 'site', 'lastModified', 'entriesCount',
507-
]);
507+
];
508508
}
509509

510510
public function getCpSearchResultBadge()

0 commit comments

Comments
 (0)