Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit b30bbd4

Browse files
phpcs fix
1 parent c05c3ba commit b30bbd4

File tree

3 files changed

+15
-16
lines changed

3 files changed

+15
-16
lines changed

src/DeepL.php

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,7 @@ public function translate(
159159
$destinationLanguage = 'en',
160160
array $tagHandling = array(),
161161
array $ignoreTags = array()
162-
)
163-
{
162+
) {
164163
// make sure we only accept supported languages
165164
$this->checkLanguages($sourceLanguage, $destinationLanguage);
166165

@@ -174,11 +173,9 @@ public function translate(
174173

175174
if ($translationsCount == 0) {
176175
throw new DeepLException('No translations found.');
177-
}
178-
else if ($translationsCount == 1) {
176+
} elseif ($translationsCount == 1) {
179177
return $translationsArray['translations'][0]['text'];
180-
}
181-
else {
178+
} else {
182179
return $translationsArray['translations'];
183180
}
184181
}
@@ -198,13 +195,17 @@ protected function checkLanguages($sourceLanguage, $destinationLanguage)
198195
$sourceLanguage = strtoupper($sourceLanguage);
199196

200197
if (!in_array($sourceLanguage, $this->sourceLanguages)) {
201-
throw new DeepLException(sprintf('The language "%s" is not supported as source language.', $sourceLanguage));
198+
throw new DeepLException(
199+
sprintf('The language "%s" is not supported as source language.', $sourceLanguage)
200+
);
202201
}
203202

204203
$destinationLanguage = strtoupper($destinationLanguage);
205204

206205
if (!in_array($destinationLanguage, $this->destinationLanguages)) {
207-
throw new DeepLException(sprintf('The language "%s" is not supported as destination language.', $destinationLanguage));
206+
throw new DeepLException(
207+
sprintf('The language "%s" is not supported as destination language.', $destinationLanguage)
208+
);
208209
}
209210

210211
return true;
@@ -225,8 +226,7 @@ protected function buildUrl(
225226
$destinationLanguage,
226227
array $tagHandling = array(),
227228
array $ignoreTags = array()
228-
)
229-
{
229+
) {
230230
// select correct api url
231231
switch ($this->apiVersion) {
232232
case 1:
@@ -271,7 +271,6 @@ protected function buildBody($text)
271271
}
272272

273273
foreach ($text as $textElement) {
274-
275274
$body .= ($first ? '' : '&') . sprintf(DeepL::API_URL_TEXT, rawurlencode($textElement));
276275

277276
if ($first) {
@@ -305,8 +304,7 @@ protected function request($url, $body)
305304
if ($httpCode != 200 && array_key_exists($httpCode, $this->errorCodes)) {
306305
throw new DeepLException($this->errorCodes[$httpCode], $httpCode);
307306
}
308-
}
309-
else {
307+
} else {
310308
throw new DeepLException('There was a cURL Request Error.');
311309
}
312310

src/DeepLException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@
1010
class DeepLException extends \Exception
1111
{
1212
// to be continued ..
13-
}
13+
}

tests/DeepLTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ public function testBuildUrl()
116116
*/
117117
public function testBuildUrlWithTags()
118118
{
119-
$expectedString = 'https://api.deepl.com/v1/translate?auth_key=123456&source_lang=de&target_lang=en&tag_handling=xml&ignore_tags=x';
119+
$expectedString = 'https://api.deepl.com';
120+
$expectedString .= '/v1/translate?auth_key=123456&source_lang=de&target_lang=en&tag_handling=xml&ignore_tags=x';
120121

121122
$authKey = '123456';
122123
$deepl = new DeepL($authKey);
@@ -254,4 +255,4 @@ public function testTranslateException()
254255

255256
$translatedText = $deepl->translate($germanText);
256257
}
257-
}
258+
}

0 commit comments

Comments
 (0)