| Total Complexity | 8 |
| Total Lines | 98 |
| Duplicated Lines | 0 % |
| Coverage | 56.67% |
| Changes | 3 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 8 | class Transliterator implements TransliteratorContract |
||
| 9 | { |
||
| 10 | /** @var string */ |
||
| 11 | const API_BASE_URI = 'http://www.alif.uz/api/'; |
||
| 12 | |||
| 13 | /** @var Client */ |
||
| 14 | private $transport; |
||
| 15 | |||
| 16 | /** @var string */ |
||
| 17 | private $text; |
||
| 18 | |||
| 19 | /** @var string */ |
||
| 20 | private $isLatToCyr = 'true'; |
||
| 21 | |||
| 22 | /** @var string */ |
||
| 23 | private $result; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Create a new instance. |
||
| 27 | */ |
||
| 28 | 15 | public function __construct() |
|
| 32 | ]); |
||
| 33 | 15 | } |
|
| 34 | |||
| 35 | /** |
||
| 36 | * @{inheritDoc} |
||
| 37 | */ |
||
| 38 | 6 | public function setText(string $text) : TransliteratorContract |
|
| 39 | { |
||
| 40 | 6 | $this->text = $text; |
|
| 41 | |||
| 42 | 6 | return $this; |
|
| 43 | } |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @{inheritDoc} |
||
| 47 | */ |
||
| 48 | 3 | public function getText() : string |
|
| 49 | { |
||
| 50 | 3 | return $this->text; |
|
| 51 | } |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @{inheritDoc} |
||
| 55 | */ |
||
| 56 | 3 | public function toLatin() : TransliteratorContract |
|
| 57 | { |
||
| 58 | 3 | $this->isLatToCyr = 'false'; |
|
| 59 | |||
| 60 | 3 | return $this; |
|
| 61 | } |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @{inheritDoc} |
||
| 65 | */ |
||
| 66 | 3 | public function toCyrillic() : TransliteratorContract |
|
| 67 | { |
||
| 68 | 3 | $this->isLatToCyr = 'true'; |
|
| 69 | |||
| 70 | 3 | return $this; |
|
| 71 | } |
||
| 72 | |||
| 73 | /** |
||
| 74 | * @{inheritDoc} |
||
| 75 | */ |
||
| 76 | public function translit() : TransliteratorContract |
||
| 77 | { |
||
| 78 | $parts = str_split_unicode($this->getText()); |
||
| 79 | $result = ""; |
||
| 80 | $response = ""; |
||
| 81 | |||
| 82 | foreach ($parts as $part) { |
||
| 83 | $response .= $this->transport |
||
| 84 | ->request('GET', 'translit', [ |
||
| 85 | 'query' => [ |
||
| 86 | 'inputText' => $part, |
||
| 87 | 'isLatToCyr' => $this->isLatToCyr, |
||
| 88 | ], |
||
| 89 | ]) |
||
| 90 | ->getBody(); |
||
| 91 | |||
| 92 | $result = dropDoubleQuotes($response); |
||
| 93 | } |
||
| 94 | |||
| 95 | $this->result = $result; |
||
| 96 | |||
| 97 | return $this; |
||
| 98 | } |
||
| 99 | |||
| 100 | /** |
||
| 101 | * @{inheritDoc} |
||
| 102 | */ |
||
| 103 | 3 | public function getResult() : string |
|
| 106 | } |
||
| 107 | } |
||
| 108 |