LotinTransliterator   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 50%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 13
c 1
b 0
f 0
dl 0
loc 39
ccs 4
cts 8
cp 0.5
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getDefaultOptions() 0 8 1
A getPerRequestOptions() 0 6 2
A getResultFromResponse() 0 3 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