-
Couldn't load subscription status.
- Fork 52
Internal attributes defaults #608
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
6d5d60e
173264b
2ecf187
1d4d7d1
ba87da6
8545413
32c6884
ed9c424
f71ee21
22b5f19
8b0bc4c
b23b8a8
42600a6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80,17 +80,17 @@ public function getCollection(): string | |
| /** | ||
| * @return array<string> | ||
| */ | ||
| public function getPermissions(): array | ||
| public function getPermissions(string $attribute = '$permissions'): array | ||
| { | ||
| return \array_values(\array_unique($this->getAttribute('$permissions', []))); | ||
| return \array_values(\array_unique($this->getAttribute($attribute, []))); | ||
| } | ||
|
|
||
| /** | ||
| * @return array<string> | ||
| */ | ||
| public function getRead(): array | ||
| public function getRead(string $attribute = '$permissions'): array | ||
| { | ||
| return $this->getPermissionsByType(Database::PERMISSION_READ); | ||
| return $this->getPermissionsByType(Database::PERMISSION_READ, $attribute); | ||
| } | ||
|
Comment on lines
+91
to
94
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Propagate the attribute parameter to the convenience helpers
If callers pass a custom attribute key to - public function getRead(string $attribute = '$permissions'): array
- {
- return $this->getPermissionsByType(Database::PERMISSION_READ, $attribute);
- }
+ public function getRead(string $attribute = '$permissions'): array
+ {
+ return $this->getPermissionsByType(Database::PERMISSION_READ, $attribute);
+ }Replicate the additional
🤖 Prompt for AI Agents |
||
|
|
||
| /** | ||
|
|
@@ -132,11 +132,11 @@ public function getWrite(): array | |
| /** | ||
| * @return array<string> | ||
| */ | ||
| public function getPermissionsByType(string $type): array | ||
| public function getPermissionsByType(string $type, string $attribute = '$permissions'): array | ||
| { | ||
| $typePermissions = []; | ||
|
|
||
| foreach ($this->getPermissions() as $permission) { | ||
| foreach ($this->getPermissions($attribute) as $permission) { | ||
| if (!\str_starts_with($permission, $type)) { | ||
| continue; | ||
| } | ||
|
|
@@ -183,13 +183,8 @@ public function getAttributes(): array | |
| { | ||
| $attributes = []; | ||
|
|
||
| $internalKeys = \array_map( | ||
| fn ($attr) => $attr['$id'], | ||
| Database::INTERNAL_ATTRIBUTES | ||
| ); | ||
|
|
||
| foreach ($this as $attribute => $value) { | ||
| if (\in_array($attribute, $internalKeys)) { | ||
| if (Database::isInternalAttribute($attribute)){ | ||
| continue; | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guard against non-array permission payloads
getPermissions()assumes the resolved attribute is always an array.If the DB adapter ever returns malformed data (e.g. a string‐encoded JSON,
null, etc.),array_unique()will raise a warning and the method will explode.Same defensive check is advisable in the other helpers that delegate to this method.
📝 Committable suggestion
🤖 Prompt for AI Agents