LotinTransliterator::getResultFromResponse()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Zvermafia\Transliteration;
4
5
use Zvermafia\Transliteration\Abstracts\HttpTransliteratorAbstract;
6
7
/**
8
 * Class LotinTransliterator
9
 * @link https://lotin.uz/ The website of the transliteration service (API)
10
 */
11
class LotinTransliterator extends HttpTransliteratorAbstract
12
{
13
    /** @var string */
14
    protected const API_URI = 'https://lotin.uz/api/translate';
15
16
    /**
17
     * @inheritDoc
18
     */
19 24
    protected function getDefaultOptions(): array
20
    {
21
        return [
22 24
            \CURLOPT_URL => self::API_URI,
23
            \CURLOPT_POST => true,
24
            \CURLOPT_HTTPHEADER => [
25
                'Accept: application/json; charset=utf-8',
26
                'Content-Type: application/json; charset=utf-8',
27
            ],
28
        ];
29
    }
30
31
    /**
32
     * @inheritDoc
33
     */
34
    protected function getPerRequestOptions(): array
35
    {
36
        return [
37
            \CURLOPT_POSTFIELDS => json_encode([
38
                'text' => $this->getText(),
39
                'mod' => $this->isToCyrillic() ? 'lattocyr' : 'cyrtolat',
40
            ]),
41
        ];
42
    }
43
44
    /**
45
     * @inheritDoc
46
     */
47 6
    protected function getResultFromResponse(string $response): string
48
    {
49 6
        return json_decode($response)->result;
50
    }
51
}
52