Skip to content

Commit 91b008c

Browse files
committed
Static modifier on some $allowed arrays
This patch is targeted at the compiler, allowing these functions to be processed faster by referencing the arrays without expecting change for them, thus being more computationally and memory efficient
1 parent db3f70d commit 91b008c

File tree

13 files changed

+21
-21
lines changed

13 files changed

+21
-21
lines changed

src/Discord/Builders/CommandAttributes.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ public function addIntegrationType(int $integration_type): self
323323
throw new \DomainException('Only globally-scopped commands can have an integration type.');
324324
}
325325

326-
$allowed = [
326+
static $allowed = [
327327
Application::INTEGRATION_TYPE_GUILD_INSTALL,
328328
Application::INTEGRATION_TYPE_USER_INSTALL,
329329
];
@@ -377,7 +377,7 @@ public function addContext(int $context): self
377377
throw new \DomainException('Only globally-scopped commands can have context.');
378378
}
379379

380-
$allowed = [
380+
static $allowed = [
381381
Interaction::CONTEXT_TYPE_GUILD,
382382
Interaction::CONTEXT_TYPE_BOT_DM,
383383
Interaction::CONTEXT_TYPE_PRIVATE_CHANNEL,
@@ -451,7 +451,7 @@ public function setHandler(?int $handler): self
451451
throw new \DomainException('Only PRIMARY_ENTRY_POINT Command type can have handler.');
452452
}
453453

454-
$allowed = [Command::APP_HANDLER, Command::DISCORD_LAUNCH_ACTIVITY];
454+
static $allowed = [Command::APP_HANDLER, Command::DISCORD_LAUNCH_ACTIVITY];
455455

456456
if (is_int($handler) && ! in_array($handler, $allowed)) {
457457
throw new \DomainException('Invalid handler provided.');

src/Discord/Builders/Components/SelectMenu.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public static function new(?string $custom_id = null): self
150150
*/
151151
public function setType(int $type): self
152152
{
153-
$allowed_types = [self::TYPE_STRING_SELECT, self::TYPE_USER_SELECT, self::TYPE_ROLE_SELECT, self::TYPE_MENTIONABLE_SELECT, self::TYPE_CHANNEL_SELECT];
153+
static $allowed_types = [self::TYPE_STRING_SELECT, self::TYPE_USER_SELECT, self::TYPE_ROLE_SELECT, self::TYPE_MENTIONABLE_SELECT, self::TYPE_CHANNEL_SELECT];
154154
if (! in_array($type, $allowed_types)) {
155155
throw new \InvalidArgumentException('Invalid select menu type.');
156156
}
@@ -245,7 +245,7 @@ public function setPlaceholder(?string $placeholder): self
245245

246246
public function setDefaultValues(?array $default_values): self
247247
{
248-
$allowed_types = [self::TYPE_USER_SELECT, self::TYPE_ROLE_SELECT, self::TYPE_MENTIONABLE_SELECT, self::TYPE_CHANNEL_SELECT];
248+
static $allowed_types = [self::TYPE_USER_SELECT, self::TYPE_ROLE_SELECT, self::TYPE_MENTIONABLE_SELECT, self::TYPE_CHANNEL_SELECT];
249249
if (! in_array($this->type, $allowed_types)) {
250250
throw new \InvalidArgumentException('Default values can only be set for user, role, mentionable, and channel selects.');
251251
}

src/Discord/CommandClient/Command.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ public function getHelp(string $prefix): array
311311
*/
312312
public function __get(string $variable)
313313
{
314-
$allowed = ['command', 'description', 'longDescription', 'usage', 'cooldown', 'cooldownMessage', 'showHelp'];
314+
static $allowed = ['command', 'description', 'longDescription', 'usage', 'cooldown', 'cooldownMessage', 'showHelp'];
315315

316316
if (in_array($variable, $allowed)) {
317317
return $this->{$variable};

src/Discord/Discord.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,7 +1225,7 @@ public function updatePresence(?Activity $activity = null, bool $idle = false, s
12251225
}
12261226
}
12271227

1228-
$allowed = ['online', 'dnd', 'idle', 'invisible', 'offline'];
1228+
static $allowed = ['online', 'dnd', 'idle', 'invisible', 'offline'];
12291229

12301230
if (! in_array($status, $allowed)) {
12311231
$status = 'online';
@@ -1685,7 +1685,7 @@ public function getCacheConfig($repository_class = AbstractRepository::class)
16851685
*/
16861686
public function __get(string $name)
16871687
{
1688-
$allowed = ['loop', 'options', 'logger', 'http', 'application_commands'];
1688+
static $allowed = ['loop', 'options', 'logger', 'http', 'application_commands'];
16891689

16901690
if (in_array($name, $allowed)) {
16911691
return $this->{$name};

src/Discord/DiscordCommandClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ public function getCommandClientOptions()
476476
*/
477477
public function __get(string $name)
478478
{
479-
$allowed = ['commands', 'aliases'];
479+
static $allowed = ['commands', 'aliases'];
480480

481481
if (in_array($name, $allowed)) {
482482
return $this->{$name};

src/Discord/Parts/Channel/Message/AllowedMentions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public function setParse($items): self
132132
*/
133133
public function addParse(...$items): self
134134
{
135-
$allowed = [self::TYPE_ROLE, self::TYPE_USER, self::TYPE_EVERYONE];
135+
static $allowed = [self::TYPE_ROLE, self::TYPE_USER, self::TYPE_EVERYONE];
136136

137137
foreach ($items as &$item) {
138138
if (!is_string($item)) {

src/Discord/Parts/Guild/Guild.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ public function getIconAttribute(?string $format = null, int $size = 1024): ?str
520520
}
521521

522522
if (isset($format)) {
523-
$allowed = ['png', 'jpg', 'webp', 'gif'];
523+
static $allowed = ['png', 'jpg', 'webp', 'gif'];
524524

525525
if (! in_array(strtolower($format), $allowed)) {
526526
$format = 'webp';
@@ -558,7 +558,7 @@ public function getSplashAttribute(string $format = 'webp', int $size = 2048): ?
558558
return null;
559559
}
560560

561-
$allowed = ['png', 'jpg', 'webp'];
561+
static $allowed = ['png', 'jpg', 'webp'];
562562

563563
if (! in_array(strtolower($format), $allowed)) {
564564
$format = 'webp';

src/Discord/Parts/Guild/Role.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public function getIconAttribute(string $format = 'png', int $size = 64): ?strin
111111
return null;
112112
}
113113

114-
$allowed = ['png', 'jpg', 'webp'];
114+
static $allowed = ['png', 'jpg', 'webp'];
115115

116116
if (! in_array(strtolower($format), $allowed)) {
117117
$format = 'png';

src/Discord/Parts/Guild/ScheduledEvent.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ public function getImageAttribute(?string $format = null, int $size = 1024): ?st
192192
return null;
193193
}
194194

195-
$allowed = ['png', 'jpg', 'webp'];
195+
static $allowed = ['png', 'jpg', 'webp'];
196196

197197
if (! in_array(strtolower($format), $allowed)) {
198198
$format = 'png';

src/Discord/Parts/OAuth/Application.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ public function getIconAttribute(string $format = 'webp', int $size = 1024): ?st
188188
return null;
189189
}
190190

191-
$allowed = ['png', 'jpg', 'webp'];
191+
static $allowed = ['png', 'jpg', 'webp'];
192192
if (! in_array(strtolower($format), $allowed)) {
193193
$format = 'webp';
194194
}
@@ -256,7 +256,7 @@ public function getCoverImageAttribute(string $format = 'webp', int $size = 1024
256256
return null;
257257
}
258258

259-
$allowed = ['png', 'jpg', 'webp'];
259+
static $allowed = ['png', 'jpg', 'webp'];
260260
if (! in_array(strtolower($format), $allowed)) {
261261
$format = 'webp';
262262
}

0 commit comments

Comments
 (0)