Skip to content
This repository was archived by the owner on Feb 18, 2023. It is now read-only.

Commit cab9495

Browse files
committed
Added php-cs-fixer
1 parent 7a1afa3 commit cab9495

File tree

10 files changed

+235
-49
lines changed

10 files changed

+235
-49
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
vendor
22
composer.lock
33
test.php
4-
.vscode
4+
.vscode
5+
.php_cs.cache

.php_cs.dist

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?php
2+
3+
$header = <<<'EOF'
4+
This file is a part of the DiscordPHP-Slash project.
5+
6+
Copyright (c) 2020-present David Cole <[email protected]>
7+
8+
This source file is subject to the GNU General Public License v3.0
9+
that is bundled with this source code in the LICENSE.md file.
10+
EOF;
11+
12+
$fixers = [
13+
'blank_line_after_namespace',
14+
'braces',
15+
'class_definition',
16+
'elseif',
17+
'encoding',
18+
'full_opening_tag',
19+
'function_declaration',
20+
'lowercase_constants',
21+
'lowercase_keywords',
22+
'method_argument_space',
23+
'no_closing_tag',
24+
'no_spaces_after_function_name',
25+
'no_spaces_inside_parenthesis',
26+
'no_trailing_whitespace',
27+
'no_trailing_whitespace_in_comment',
28+
'single_blank_line_at_eof',
29+
'single_class_element_per_statement',
30+
'single_import_per_statement',
31+
'single_line_after_imports',
32+
'switch_case_semicolon_to_colon',
33+
'switch_case_space',
34+
'visibility_required',
35+
'blank_line_after_opening_tag',
36+
'no_multiline_whitespace_around_double_arrow',
37+
'no_empty_statement',
38+
'no_extra_consecutive_blank_lines',
39+
'include',
40+
'no_trailing_comma_in_list_call',
41+
'not_operator_with_successor_space',
42+
'trailing_comma_in_multiline_array',
43+
'no_multiline_whitespace_before_semicolons',
44+
'no_leading_namespace_whitespace',
45+
'no_blank_lines_after_class_opening',
46+
'no_blank_lines_after_phpdoc',
47+
'object_operator_without_whitespace',
48+
'binary_operator_spaces',
49+
'phpdoc_indent',
50+
'phpdoc_inline_tag',
51+
'phpdoc_no_access',
52+
'phpdoc_no_package',
53+
'phpdoc_scalar',
54+
'phpdoc_summary',
55+
'phpdoc_to_comment',
56+
'phpdoc_trim',
57+
'phpdoc_var_without_name',
58+
'no_leading_import_slash',
59+
'blank_line_before_return',
60+
'no_short_echo_tag',
61+
'no_trailing_comma_in_singleline_array',
62+
'single_blank_line_before_namespace',
63+
'single_quote',
64+
'no_singleline_whitespace_before_semicolons',
65+
'cast_spaces',
66+
'standardize_not_equals',
67+
'ternary_operator_spaces',
68+
'trim_array_spaces',
69+
'unary_operator_spaces',
70+
'no_unused_imports',
71+
'no_useless_else',
72+
'no_useless_return',
73+
'phpdoc_no_empty_return',
74+
];
75+
76+
$rules = [
77+
'concat_space' => ['spacing' => 'none'],
78+
'phpdoc_no_alias_tag' => ['type' => 'var'],
79+
'array_syntax' => ['syntax' => 'short'],
80+
'binary_operator_spaces' => ['align_double_arrow' => true, 'align_equals' => true],
81+
'header_comment' => ['header' => $header],
82+
'indentation_type' => true,
83+
'phpdoc_align' => [
84+
'align' => 'vertical'
85+
]
86+
];
87+
88+
foreach ($fixers as $fix) {
89+
$rules[$fix] = true;
90+
}
91+
92+
return PhpCsFixer\Config::create()
93+
->setRules($rules)
94+
->setFinder(
95+
PhpCsFixer\Finder::create()
96+
->in(__DIR__)
97+
);

src/Discord/Client.php

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
<?php
22

3+
/*
4+
* This file is a part of the DiscordPHP-Slash project.
5+
*
6+
* Copyright (c) 2020-present David Cole <[email protected]>
7+
*
8+
* This source file is subject to the GNU General Public License v3.0
9+
* that is bundled with this source code in the LICENSE.md file.
10+
*/
11+
312
namespace Discord\Slash;
413

514
use Discord\Interaction as DiscordInteraction;
@@ -33,7 +42,7 @@
3342
*/
3443
class Client
3544
{
36-
const API_BASE_URI = "https://discord.com/api/v8/";
45+
const API_BASE_URI = 'https://discord.com/api/v8/';
3746

3847
/**
3948
* Array of options for the client.
@@ -59,13 +68,13 @@ class Client
5968
/**
6069
* An array of registered commands.
6170
*
62-
* @var RegisteredCommand[]
71+
* @var RegisteredCommand[]
6372
*/
6473
private $commands;
6574

6675
/**
6776
* Logger for client.
68-
*
77+
*
6978
* @var LoggerInterface
7079
*/
7180
private $logger;
@@ -150,6 +159,7 @@ public function handleRequest(ServerRequestInterface $request)
150159

151160
return $this->handleInteraction($interaction)->then(function ($result) {
152161
$this->logger->info('responding to interaction', $result);
162+
153163
return new Response(200, [], json_encode($result));
154164
});
155165
}
@@ -158,19 +168,20 @@ public function handleRequest(ServerRequestInterface $request)
158168
* Handles an interaction from Discord.
159169
*
160170
* @param Interaction $interaction
161-
*
171+
*
162172
* @return ExtendedPromiseInterface
163173
*/
164174
private function handleInteraction(Interaction $interaction): ExtendedPromiseInterface
165175
{
166-
return new Promise(function ($resolve, $reject) use ($interaction) {
176+
return new Promise(function ($resolve, $reject) use ($interaction) {
167177
switch ($interaction->type) {
168178
case InteractionType::PING:
169179
return $resolve([
170180
'type' => InteractionResponseType::PONG,
171181
]);
172182
case InteractionType::APPLICATION_COMMAND:
173183
$interaction->setResolve($resolve);
184+
174185
return $this->handleApplicationCommand($interaction);
175186
}
176187
});
@@ -185,11 +196,15 @@ private function handleApplicationCommand(Interaction $interaction): void
185196
{
186197
$checkCommand = function ($command) use ($interaction, &$checkCommand) {
187198
if (isset($this->commands[$command['name']])) {
188-
if ($this->commands[$command['name']]->execute($command['options'] ?? [], $interaction)) return true;
199+
if ($this->commands[$command['name']]->execute($command['options'] ?? [], $interaction)) {
200+
return true;
201+
}
189202
}
190203

191204
foreach ($command['options'] ?? [] as $option) {
192-
if ($checkCommand($option)) return true;
205+
if ($checkCommand($option)) {
206+
return true;
207+
}
193208
}
194209
};
195210

@@ -200,17 +215,21 @@ private function handleApplicationCommand(Interaction $interaction): void
200215
* Registeres a command with the client.
201216
*
202217
* @param string|array $name
203-
* @param callable $callback
204-
*
218+
* @param callable $callback
219+
*
205220
* @return RegisteredCommand
206221
*/
207-
public function registerCommand($name, callable $callback = null): RegisteredCommand
222+
public function registerCommand($name, callable $callback = null): RegisteredCommand
208223
{
209-
if (is_array($name) && count($name) == 1) $name = array_shift($name);
224+
if (is_array($name) && count($name) == 1) {
225+
$name = array_shift($name);
226+
}
210227

211228
// registering base command
212229
if (! is_array($name) || count($name) == 1) {
213-
if (isset($this->commands[$name])) throw new InvalidArgumentException("The command `{$name}` already exists.");
230+
if (isset($this->commands[$name])) {
231+
throw new InvalidArgumentException("The command `{$name}` already exists.");
232+
}
214233

215234
return $this->commands[$name] = new RegisteredCommand($name, $callback);
216235
}

src/Discord/Enums/ApplicationCommandOptionType.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
<?php
22

3+
/*
4+
* This file is a part of the DiscordPHP-Slash project.
5+
*
6+
* Copyright (c) 2020-present David Cole <[email protected]>
7+
*
8+
* This source file is subject to the GNU General Public License v3.0
9+
* that is bundled with this source code in the LICENSE.md file.
10+
*/
11+
312
namespace Discord\Slash\Enums;
413

514
/**

src/Discord/Parts/Choices.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
<?php
22

3+
/*
4+
* This file is a part of the DiscordPHP-Slash project.
5+
*
6+
* Copyright (c) 2020-present David Cole <[email protected]>
7+
*
8+
* This source file is subject to the GNU General Public License v3.0
9+
* that is bundled with this source code in the LICENSE.md file.
10+
*/
11+
312
namespace Discord\Slash\Parts;
413

514
/**
615
* Choices represents an array of choices that can be given to a command.
7-
*
16+
*
817
* @author David Cole <[email protected]>
918
*/
1019
class Choices
@@ -30,7 +39,7 @@ public function __construct(array $choices)
3039
* Handles dynamic get requests to the class.
3140
*
3241
* @param string $name
33-
*
42+
*
3443
* @return string|int|null
3544
*/
3645
public function __get($name)
@@ -45,7 +54,7 @@ public function __get($name)
4554
}
4655

4756
/**
48-
* Returns the info to appear when the class is `var_dump`'d
57+
* Returns the info to appear when the class is `var_dump`'d.
4958
*
5059
* @return array
5160
*/
@@ -59,4 +68,4 @@ public function __debugInfo()
5968

6069
return $response;
6170
}
62-
}
71+
}

src/Discord/Parts/Command.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
<?php
22

3+
/*
4+
* This file is a part of the DiscordPHP-Slash project.
5+
*
6+
* Copyright (c) 2020-present David Cole <[email protected]>
7+
*
8+
* This source file is subject to the GNU General Public License v3.0
9+
* that is bundled with this source code in the LICENSE.md file.
10+
*/
11+
312
namespace Discord\Slash\Parts;
413

514
/**
615
* Represents a command registered on the Discord servers.
7-
*
16+
*
817
* @author David Cole <[email protected]>
918
*/
1019
class Command extends Part

src/Discord/Parts/Interaction.php

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
<?php
22

3+
/*
4+
* This file is a part of the DiscordPHP-Slash project.
5+
*
6+
* Copyright (c) 2020-present David Cole <[email protected]>
7+
*
8+
* This source file is subject to the GNU General Public License v3.0
9+
* that is bundled with this source code in the LICENSE.md file.
10+
*/
11+
312
namespace Discord\Slash\Parts;
413

514
use Discord\InteractionResponseType;
615

716
/**
817
* An interaction sent from Discord servers.
9-
*
18+
*
1019
* @property string $id
1120
* @property string $type
1221
* @property array $data
@@ -51,11 +60,11 @@ public function acknowledge(bool $source = false)
5160
/**
5261
* Replies to the interaction with a message.
5362
*
54-
* @param string $content
55-
* @param bool $tts
63+
* @param string $content
64+
* @param bool $tts
5665
* @param array|null $embed
5766
* @param array|null $allowed_mentions
58-
* @param bool $source
67+
* @param bool $source
5968
*/
6069
public function reply(string $content, bool $tts = false, ?array $embed = null, ?array $allowed_mentions = null, bool $source = false)
6170
{
@@ -82,13 +91,13 @@ public function reply(string $content, bool $tts = false, ?array $embed = null,
8291
* Replies to the interaction with a message and shows the source message.
8392
* Alias for `reply()` with source = true.
8493
*
85-
* @param string $content
86-
* @param boolean $tts
94+
* @param string $content
95+
* @param bool $tts
8796
* @param array|null $embed
8897
* @param array|null $allowed_mentions
8998
*/
9099
public function replyWithSource(string $content, bool $tts = false, ?array $embed = null, ?array $allowed_mentions = null)
91100
{
92101
$this->reply($content, $tts, $embed, $allowed_mentions, true);
93102
}
94-
}
103+
}

src/Discord/Parts/Part.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
<?php
22

3+
/*
4+
* This file is a part of the DiscordPHP-Slash project.
5+
*
6+
* Copyright (c) 2020-present David Cole <[email protected]>
7+
*
8+
* This source file is subject to the GNU General Public License v3.0
9+
* that is bundled with this source code in the LICENSE.md file.
10+
*/
11+
312
namespace Discord\Slash\Parts;
413

514
use JsonSerializable;
615

716
/**
817
* Represents a part in the Discord servers.
9-
*
18+
*
1019
* @author David Cole <[email protected]>
1120
*/
1221
class Part implements JsonSerializable
@@ -52,7 +61,7 @@ public function __get(string $key)
5261
* Sets an attribute in the part.
5362
*
5463
* @param string $key
55-
* @param mixed $value
64+
* @param mixed $value
5665
*/
5766
public function __set(string $key, $value)
5867
{

0 commit comments

Comments
 (0)