8000 Suggestions by Review @OskarStark · symfony/symfony@777f2be · GitHub
[go: up one dir, main page]

Skip to content

Commit 777f2be

Browse files
committed
Suggestions by Review @OskarStark
1 parent b341c9a commit 777f2be

File tree

1 file changed

+27
-48
lines changed

1 file changed

+27
-48
lines changed

src/Symfony/Component/Notifier/Bridge/Matrix/MatrixTransport.php

Lines changed: 27 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,15 @@ protected function doSend(MessageInterface $message): SentMessage
8484
default => throw new UnsupportedRecipientTypeException($message->getRecipientId()[0]),
8585
};
8686

87+
$options['body'] = $message->getSubject();
8788
if ('org.matrix.custom.html' === $options['format']) {
8889
$options['formatted_body'] = $message->getSubject();
8990
$options['body'] = strip_tags($message->getSubject());
90-
} else {
91-
$options['body'] = $message->getSubject();
9291
}
9392

94-
$uri = '/_matrix/client/v3/rooms/%s/send/%s/%s';
95-
$response = $this->connect(
93+
$response = $this->request(
9694
method: 'PUT',
97-
uri: \sprintf($uri, $recipient, 'm.room.message', Uuid::v4()),
95+
uri: \sprintf('/_matrix/client/v3/rooms/%s/send/%s/%s', $recipient, 'm.room.message', Uuid::v4()),
9896
options: [
9997
'json' => $options,
10098
]
@@ -107,21 +105,17 @@ protected function doSend(MessageInterface $message): SentMessage
107105
return $sentMessage;
108106
}
109107

110-
private function getRoomFromAlias(
111-
string $alias,
112-
): string {
113-
$uri = '/_matrix/client/v3/directory/room/%s';
114-
$response = $this->connect('GET', \sprintf($uri, urlencode($alias)));
108+
private function getRoomFromAlias(string $alias): string
109+
{
110+
$response = $this->request('GET', \sprintf('/_matrix/client/v3/directory/room/%s', urlencode($alias)));
115111

116112
return $response->toArray()['room_id'];
117113
}
118114

119-
private function createPrivateChannel(
120-
string $recipientId,
121-
): ?array {
122-
$uri = '/_matrix/client/v3/createRoom';
115+
private function createPrivateChannel(string $recipientId): ?array
116+
{
123117
$invites[] = $recipientId;
124-
$response = $this->connect('POST', $uri, [
118+
$response = $this->request('POST', '/_matrix/client/v3/createRoom', [
125119
'json' => [
126120
'creation_content' => [
127121
'm.federate' => false,
@@ -135,9 +129,8 @@ private function createPrivateChannel(
135129
return $response->toArray();
136130
}
137131

138-
private function getDirectMessageChannel(
139-
string $recipientId,
140-
): ?string {
132+
private function getDirectMessageChannel(string $recipientId): ?string
133+
{
141134
$response = $this->getAccountData($this->getWhoami()['user_id'], 'm.direct');
142135
if (!isset($response[$recipientId])) {
143136
$roomid = $this->createPrivateChannel($recipientId)['room_id'];
@@ -150,15 +143,11 @@ private function getDirectMessageChannel(
150143
return $response[$recipientId][0];
151144
}
152145

153-
private function updateAccountData(
154-
string $userId,
155-
string $type,
156-
array $data,
157-
): void {
158-
$uri = '/_matrix/client/v3/user/%s/account_data/%s';
159-
$response = $this->connect(
146+
private function updateAccountData(string $userId, string $type, array $data): void
147+
{
148+
$response = $this->request(
160149
method: 'PUT',
161-
uri: \sprintf($uri, urlencode($userId), $type),
150+
uri: \sprintf('/_matrix/client/v3/user/%s/account_data/%s', urlencode($userId), $type),
162151
options: [
163152
'json' => $data,
164153
]);
@@ -167,52 +156,42 @@ private function updateAccountData(
167156
}
168157
}
169158

170-
private function getAccountData(
171-
string $userId,
172-
string $type,
173-
): ?array {
174-
$uri = '/_matrix/client/v3/user/%s/account_data/%s';
175-
$response = $this->connect(
159+
private function getAccountData(string $userId, string $type): ?array
160+
{
161+
$response = $this->request(
176162
method: 'GET',
177-
uri: \sprintf($uri, urlencode($userId), $type));
163+
uri: \sprintf('/_matrix/client/v3/user/%s/account_data/%s', urlencode($userId), $type));
178164

179165
return $response->toArray();
180166
}
181167

182-
protected function getWhoami(): ?array
168+
private function getWhoami(): ?array
183169
{
184-
$uri = '/_matrix/client/v3/account/whoami';
185-
$response = $this->connect(
170+
$response = $this->request(
186171
method: 'GET',
187-
uri: $uri,
172+
uri: '/_matrix/client/v3/account/whoami',
188173
);
189174

190175
return $response->toArray();
191176
}
192177

193-
protected function getEndpoint(
194-
bool $full = false,
195-
): string {
178+
protected function getEndpoint(bool $full = false): string {
196179
return rtrim(
197180
($full ? $this->getScheme().'://' : '').$this->host.($this->port ? ':'.$this->port : ''),
198181
'/');
199182
}
200183

201-
protected function getScheme(): string
184+
private function getScheme(): string
202185
{
203186
return $this->ssl ? 'https' : 'http';
204187
}
205188

206-
protected function connect(
207-
string $method,
208-
string $uri,
209-
?array $options = [],
210-
): ResponseInterface {
189+
private function request(string $method, string $uri, ?array $options = []): ResponseInterface
190+
{
211191
$options += [
212192
'auth_bearer' => $this->accessToken,
213193
];
214-
$url = $this->getEndpoint(true).$uri;
215-
$response = $this->client->request($method, $url, $options);
194+
$response = $this->client->request($method, $this->getEndpoint(true).$uri, $options);
216195

217196
try {
218197
$statusCode = $response->getStatusCode();

0 commit comments

Comments
 (0)
0