@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | */ |
46 | 46 | public function setMessagesPerPage(int $messagesPerPage): void |
47 | 47 | { |
48 | - if ($messagesPerPage < 0) { |
|
48 | + if($messagesPerPage < 0) { |
|
49 | 49 | $messagesPerPage = 0; |
50 | 50 | } |
51 | 51 | $this->messagesPerPage = $messagesPerPage; |
@@ -102,9 +102,9 @@ discard block |
||
102 | 102 | |
103 | 103 | protected function processMessage(string $message): ?string |
104 | 104 | { |
105 | - foreach ($this->messageProcessors as $processor) { |
|
105 | + foreach($this->messageProcessors as $processor) { |
|
106 | 106 | $result = $processor->parse($message); |
107 | - if (is_string($result)) { |
|
107 | + if(is_string($result)) { |
|
108 | 108 | return $result; |
109 | 109 | } |
110 | 110 | } |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | public function newMessage(string $message): void |
118 | 118 | { |
119 | 119 | $result = $this->processMessage($message); |
120 | - if ($result !== null) { |
|
120 | + if($result !== null) { |
|
121 | 121 | $this->presenter->flashMessage($result); |
122 | 122 | } else { |
123 | 123 | $this->database->addMessage($message, $this->textColumn, $this->textValue); |
@@ -8,8 +8,7 @@ |
||
8 | 8 | * |
9 | 9 | * @author Jakub Konečný |
10 | 10 | */ |
11 | -interface ChatMessageProcessor |
|
12 | -{ |
|
11 | +interface ChatMessageProcessor { |
|
13 | 12 | /** |
14 | 13 | * @return null|string The result/null if the processor is not applicable |
15 | 14 | */ |
@@ -4,7 +4,7 @@ |
||
4 | 4 | |
5 | 5 | namespace HeroesofAbenez\Chat; |
6 | 6 | |
7 | -if (false) { |
|
7 | +if(false) { |
|
8 | 8 | /** @deprecated use DatabaseAdapter */ |
9 | 9 | interface IDatabaseAdapter extends DatabaseAdapter |
10 | 10 | { |
@@ -6,8 +6,7 @@ |
||
6 | 6 | |
7 | 7 | if (false) { |
8 | 8 | /** @deprecated use DatabaseAdapter */ |
9 | - interface IDatabaseAdapter extends DatabaseAdapter |
|
10 | - { |
|
9 | + interface IDatabaseAdapter extends DatabaseAdapter { |
|
11 | 10 | } |
12 | 11 | |
13 | 12 | } else { |
@@ -8,8 +8,7 @@ |
||
8 | 8 | * |
9 | 9 | * @author Jakub Konečný |
10 | 10 | */ |
11 | -class ChatMessage |
|
12 | -{ |
|
11 | +class ChatMessage { |
|
13 | 12 | use \Nette\SmartObject; |
14 | 13 | |
15 | 14 | public function __construct( |
@@ -8,8 +8,7 @@ |
||
8 | 8 | * |
9 | 9 | * @author Jakub Konečný |
10 | 10 | */ |
11 | -final class ChatCommandsProcessor implements ChatMessageProcessor |
|
12 | -{ |
|
11 | +final class ChatCommandsProcessor implements ChatMessageProcessor { |
|
13 | 12 | /** @var IChatCommand[] */ |
14 | 13 | private array $commands = []; |
15 | 14 |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | public function addCommand(IChatCommand $command): void |
22 | 22 | { |
23 | 23 | $name = $command->getName(); |
24 | - if ($this->hasCommand($name)) { |
|
24 | + if($this->hasCommand($name)) { |
|
25 | 25 | throw new CommandNameAlreadyUsedException("Command $name is already defined."); |
26 | 26 | } |
27 | 27 | $this->commands[] = $command; |
@@ -46,16 +46,16 @@ discard block |
||
46 | 46 | */ |
47 | 47 | public function extractCommand(string $text): string |
48 | 48 | { |
49 | - if (!str_starts_with($text, "/")) { |
|
49 | + if(!str_starts_with($text, "/")) { |
|
50 | 50 | return ""; |
51 | 51 | } |
52 | - if (!str_contains($text, " ")) { |
|
52 | + if(!str_contains($text, " ")) { |
|
53 | 53 | $command = substr($text, 1); |
54 | 54 | } else { |
55 | 55 | $parts = explode(" ", substr($text, 1)); |
56 | 56 | $command = $parts[0]; |
57 | 57 | } |
58 | - if ($this->hasCommand($command)) { |
|
58 | + if($this->hasCommand($command)) { |
|
59 | 59 | return $command; |
60 | 60 | } |
61 | 61 | return ""; |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | */ |
68 | 68 | public function extractParameters(string $text): array |
69 | 69 | { |
70 | - if (!str_starts_with($text, "/") || !str_contains($text, " ")) { |
|
70 | + if(!str_starts_with($text, "/") || !str_contains($text, " ")) { |
|
71 | 71 | return []; |
72 | 72 | } |
73 | 73 | $params = explode(" ", $text); |
@@ -80,8 +80,8 @@ discard block |
||
80 | 80 | */ |
81 | 81 | public function hasCommand(string $name): bool |
82 | 82 | { |
83 | - foreach ($this->commands as $command) { |
|
84 | - if ($command->getName() === $name) { |
|
83 | + foreach($this->commands as $command) { |
|
84 | + if($command->getName() === $name) { |
|
85 | 85 | return true; |
86 | 86 | } |
87 | 87 | } |
@@ -95,8 +95,8 @@ discard block |
||
95 | 95 | */ |
96 | 96 | public function getCommand(string $name): IChatCommand |
97 | 97 | { |
98 | - foreach ($this->commands as $command) { |
|
99 | - if ($command->getName() === $name) { |
|
98 | + foreach($this->commands as $command) { |
|
99 | + if($command->getName() === $name) { |
|
100 | 100 | return $command; |
101 | 101 | } |
102 | 102 | } |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | public function parse(string $message): ?string |
107 | 107 | { |
108 | 108 | $commandName = $this->extractCommand($message); |
109 | - if ($commandName === "") { |
|
109 | + if($commandName === "") { |
|
110 | 110 | return null; |
111 | 111 | } |
112 | 112 | $command = $this->getCommand($commandName); |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | { |
23 | 23 | $name = $command->getName(); |
24 | 24 | if ($this->hasCommand($name)) { |
25 | - throw new CommandNameAlreadyUsedException("Command $name is already defined."); |
|
25 | + throw new CommandNameAlreadyUsedException("command $name is already defined."); |
|
26 | 26 | } |
27 | 27 | $this->commands[] = $command; |
28 | 28 | } |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | return $command; |
101 | 101 | } |
102 | 102 | } |
103 | - throw new CommandNotFoundException("Command $name is not defined."); |
|
103 | + throw new CommandNotFoundException("command $name is not defined."); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | public function parse(string $message): ?string |
@@ -8,8 +8,7 @@ |
||
8 | 8 | * |
9 | 9 | * @author Jakub Konečný |
10 | 10 | */ |
11 | -interface DatabaseAdapter |
|
12 | -{ |
|
11 | +interface DatabaseAdapter { |
|
13 | 12 | /** |
14 | 13 | * @param mixed $value |
15 | 14 | */ |
@@ -10,8 +10,7 @@ |
||
10 | 10 | * @author Jakub Konečný |
11 | 11 | * @internal |
12 | 12 | */ |
13 | -final class Config |
|
14 | -{ |
|
13 | +final class Config { |
|
15 | 14 | /** |
16 | 15 | * @var class-string[] |
17 | 16 | */ |
@@ -52,11 +52,11 @@ discard block |
||
52 | 52 | { |
53 | 53 | try { |
54 | 54 | $rm = new \ReflectionMethod($interface, "create"); |
55 | - } catch (\ReflectionException $e) { |
|
55 | + } catch(\ReflectionException $e) { |
|
56 | 56 | throw new InvalidChatControlFactoryException("Interface $interface does not contain method create.", 0, $e); |
57 | 57 | } |
58 | 58 | $returnType = $rm->getReturnType(); |
59 | - if ($returnType === null || !is_subclass_of($returnType->getName(), ChatControl::class)) { |
|
59 | + if($returnType === null || !is_subclass_of($returnType->getName(), ChatControl::class)) { |
|
60 | 60 | throw new InvalidChatControlFactoryException( |
61 | 61 | "Return type of $interface::create() is not a subtype of " . ChatControl::class . "." |
62 | 62 | ); |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | private function getChats(): array |
70 | 70 | { |
71 | 71 | $chats = []; |
72 | - foreach ($this->config->chats as $name => $interface) { |
|
72 | + foreach($this->config->chats as $name => $interface) { |
|
73 | 73 | $this->validateFactory($interface); |
74 | 74 | $chats[$name] = $interface; |
75 | 75 | } |
@@ -82,8 +82,8 @@ discard block |
||
82 | 82 | private function getMessageProcessors(): array |
83 | 83 | { |
84 | 84 | $messageProcessors = []; |
85 | - foreach ($this->config->messageProcessors as $name => $processor) { |
|
86 | - if (!is_subclass_of($processor, ChatMessageProcessor::class)) { |
|
85 | + foreach($this->config->messageProcessors as $name => $processor) { |
|
86 | + if(!is_subclass_of($processor, ChatMessageProcessor::class)) { |
|
87 | 87 | throw new InvalidMessageProcessorException("Invalid message processor $processor."); |
88 | 88 | } |
89 | 89 | $messageProcessors[$name] = $processor; |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | private function getDatabaseAdapter(): string |
98 | 98 | { |
99 | 99 | $adapter = $this->config->databaseAdapter; |
100 | - if (!is_subclass_of($adapter, DatabaseAdapter::class)) { |
|
100 | + if(!is_subclass_of($adapter, DatabaseAdapter::class)) { |
|
101 | 101 | throw new InvalidDatabaseAdapterException("Invalid database adapter $adapter."); |
102 | 102 | } |
103 | 103 | return $adapter; |
@@ -113,16 +113,16 @@ discard block |
||
113 | 113 | $builder = $this->getContainerBuilder(); |
114 | 114 | $chats = $this->getChats(); |
115 | 115 | $characterProfileLink = $this->config->characterProfileLink; |
116 | - foreach ($chats as $name => $interface) { |
|
116 | + foreach($chats as $name => $interface) { |
|
117 | 117 | $chat = $builder->addFactoryDefinition($this->prefix($name)) |
118 | 118 | ->setImplement($interface) |
119 | 119 | ->addTag(self::TAG_CHAT); |
120 | - if ($characterProfileLink !== "") { |
|
120 | + if($characterProfileLink !== "") { |
|
121 | 121 | $chat->getResultDefinition()->addSetup("setCharacterProfileLink", [$characterProfileLink]); |
122 | 122 | } |
123 | 123 | } |
124 | 124 | $messageProcessors = $this->getMessageProcessors(); |
125 | - foreach ($messageProcessors as $name => $processor) { |
|
125 | + foreach($messageProcessors as $name => $processor) { |
|
126 | 126 | $builder->addDefinition($this->prefix($name)) |
127 | 127 | ->setType($processor); |
128 | 128 | } |
@@ -138,10 +138,10 @@ discard block |
||
138 | 138 | $builder = $this->getContainerBuilder(); |
139 | 139 | $chats = $this->getChats(); |
140 | 140 | $messageProcessors = $this->getMessageProcessors(); |
141 | - foreach ($chats as $chat => $chatClass) { |
|
141 | + foreach($chats as $chat => $chatClass) { |
|
142 | 142 | /** @var FactoryDefinition $chatService */ |
143 | 143 | $chatService = $builder->getDefinition($this->prefix($chat)); |
144 | - foreach ($messageProcessors as $processor => $processorClass) { |
|
144 | + foreach($messageProcessors as $processor => $processorClass) { |
|
145 | 145 | $processorService = $builder->getDefinition($this->prefix($processor)); |
146 | 146 | $chatService->getResultDefinition()->addSetup("addMessageProcessor", [$processorService]); |
147 | 147 | } |
@@ -154,11 +154,11 @@ discard block |
||
154 | 154 | try { |
155 | 155 | /** @var ServiceDefinition $processor */ |
156 | 156 | $processor = $builder->getDefinition($this->prefix(self::SERVICE_CHAT_COMMANDS_PROCESSOR)); |
157 | - } catch (MissingServiceException) { |
|
157 | + } catch(MissingServiceException) { |
|
158 | 158 | return; |
159 | 159 | } |
160 | 160 | $chatCommands = $builder->findByType(IChatCommand::class); |
161 | - foreach ($chatCommands as $command) { |
|
161 | + foreach($chatCommands as $command) { |
|
162 | 162 | $processor->addSetup("addCommand", [$command]); |
163 | 163 | } |
164 | 164 | } |
@@ -53,7 +53,7 @@ |
||
53 | 53 | try { |
54 | 54 | $rm = new \ReflectionMethod($interface, "create"); |
55 | 55 | } catch (\ReflectionException $e) { |
56 | - throw new InvalidChatControlFactoryException("Interface $interface does not contain method create.", 0, $e); |
|
56 | + throw new InvalidChatControlFactoryException("interface $interface does not contain method create.", 0, $e); |
|
57 | 57 | } |
58 | 58 | $returnType = $rm->getReturnType(); |
59 | 59 | if ($returnType === null || !is_subclass_of($returnType->getName(), ChatControl::class)) { |
@@ -4,7 +4,7 @@ |
||
4 | 4 | |
5 | 5 | namespace HeroesofAbenez\Chat; |
6 | 6 | |
7 | -if (false) { |
|
7 | +if(false) { |
|
8 | 8 | /** @deprecated use ChatMessageProcessor */ |
9 | 9 | interface IChatMessageProcessor extends ChatMessageProcessor |
10 | 10 | { |
@@ -6,8 +6,7 @@ |
||
6 | 6 | |
7 | 7 | if (false) { |
8 | 8 | /** @deprecated use ChatMessageProcessor */ |
9 | - interface IChatMessageProcessor extends ChatMessageProcessor |
|
10 | - { |
|
9 | + interface IChatMessageProcessor extends ChatMessageProcessor { |
|
11 | 10 | } |
12 | 11 | |
13 | 12 | } else { |