Skip to content

Commit 461ca96

Browse files
authored
Merge pull request #1175 from SQKo/optimize-role-permission-values
replace Role::permissions setter with getter to save up memory
2 parents 6234b07 + 1e9a330 commit 461ca96

File tree

1 file changed

+10
-23
lines changed

1 file changed

+10
-23
lines changed

src/Discord/Parts/Guild/Role.php

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,15 @@ class Role extends Part
6161
];
6262

6363
/**
64-
* Sets the permissions attribute.
64+
* Gets the permissions attribute.
6565
*
66-
* @param RolePermission|int $permission The permissions to set.
66+
* @return RolePermission The role permission.
67+
*
68+
* @since 10.0.0 Replaced setPermissionsAttribute() to save up memory.
6769
*/
68-
protected function setPermissionsAttribute($permission): void
70+
protected function getPermissionsAttribute(): Part
6971
{
70-
if (! ($permission instanceof RolePermission)) {
71-
$permission = $this->createOf(RolePermission::class, ['bitwise' => $permission]);
72-
}
73-
74-
$this->attributes['permissions'] = $permission;
72+
return $this->createOf(RolePermission::class, ['bitwise' => $this->attributes['permissions']]);
7573
}
7674

7775
/**
@@ -138,10 +136,10 @@ public function getCreatableAttributes(): array
138136
{
139137
return $this->makeOptionalAttributes([
140138
'name' => $this->name,
141-
'permissions' => (string) $this->permissions,
139+
'permissions' => (string) $this->getPermissionsAttribute(),
142140
'color' => $this->color,
143141
'hoist' => $this->hoist,
144-
'icon' => $this->icon_hash,
142+
'icon' => $this->getIconHashAttribute(),
145143
'unicode_emoji' => $this->unicode_emoji,
146144
'mentionable' => $this->mentionable,
147145
]);
@@ -156,10 +154,10 @@ public function getUpdatableAttributes(): array
156154
{
157155
return $this->makeOptionalAttributes([
158156
'name' => $this->name,
159-
'permissions' => (string) $this->permissions,
157+
'permissions' => (string) $this->getPermissionsAttribute(),
160158
'color' => $this->color,
161159
'hoist' => $this->hoist,
162-
'icon' => $this->icon_hash,
160+
'icon' => $this->getIconHashAttribute(),
163161
'unicode_emoji' => $this->unicode_emoji,
164162
'mentionable' => $this->mentionable,
165163
]);
@@ -184,15 +182,4 @@ public function __toString(): string
184182
{
185183
return "<@&{$this->id}>";
186184
}
187-
188-
/**
189-
* {@inheritDoc}
190-
*/
191-
public function getRawAttributes(): array
192-
{
193-
$attributes = $this->attributes;
194-
$attributes['permissions'] = (string) $attributes['permissions'];
195-
196-
return $attributes;
197-
}
198185
}

0 commit comments

Comments
 (0)