DictionaryApiAbstract::getTranslateAlternatives()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 3
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
1
<?php
2
3
namespace GinoPane\PHPolyglot\API\Implementation\Dictionary;
4
5
use GinoPane\NanoRest\Request\RequestContext;
6
use GinoPane\NanoRest\Exceptions\TransportException;
7
use GinoPane\PHPolyglot\API\Implementation\ApiAbstract;
8
use GinoPane\NanoRest\Response\ResponseContextAbstract;
9
use GinoPane\PHPolyglot\Supplemental\Language\Language;
10
use GinoPane\NanoRest\Exceptions\ResponseContextException;
11
use GinoPane\PHPolyglot\Exception\BadResponseContextException;
12
use GinoPane\PHPolyglot\Exception\MethodDoesNotExistException;
13
use GinoPane\PHPolyglot\API\Response\Dictionary\DictionaryResponse;
14
15
/**
16
 * Interface DictionaryApiInterface
17
 *
18
 * @author Sergey <Gino Pane> Karavay
19
 */
20
abstract class DictionaryApiAbstract extends ApiAbstract implements DictionaryApiInterface
21
{
22
    /**
23
     * Gets text alternatives
24
     *
25
     * @param string   $text
26
     * @param Language $language
27
     *
28
     * @throws TransportException
29
     * @throws ResponseContextException
30
     * @throws BadResponseContextException
31
     * @throws MethodDoesNotExistException
32
     *
33
     * @return DictionaryResponse
34
     */
35
    public function getTextAlternatives(
36
        string $text,
37
        Language $language
38
    ): DictionaryResponse {
39
        /** @var DictionaryResponse $response */
40
        $response = $this->callApi(__FUNCTION__, func_get_args());
41
42
        return $response;
43
    }
44
45
    /**
46
     * Gets text translate alternatives
47
     *
48
     * @param string   $text
49
     * @param Language $languageTo
50
     * @param Language $languageFrom
51
     *
52
     * @throws TransportException
53
     * @throws ResponseContextException
54
     * @throws BadResponseContextException
55
     * @throws MethodDoesNotExistException
56
     *
57
     * @return DictionaryResponse
58
     */
59
    public function getTranslateAlternatives(
60
        string $text,
61
        Language $languageTo,
62
        Language $languageFrom
63
    ): DictionaryResponse {
64
        /** @var DictionaryResponse $response */
65
        $response = $this->callApi(__FUNCTION__, func_get_args());
66
67
        return $response;
68
    }
69
70
    /**
71
     * Create request context for get-text-alternatives request
72
     *
73
     * @param string   $text
74
     * @param Language $language
75
     *
76
     * @return RequestContext
77
     */
78
    abstract protected function createGetTextAlternativesContext(
79
        string $text,
80
        Language $language
81
    ): RequestContext;
82
83
    /**
84
     * Process response of get-text-alternatives request and prepare valid response
85
     *
86
     * @param ResponseContextAbstract $context
87
     *
88
     * @return DictionaryResponse
89
     */
90
    abstract protected function prepareGetTextAlternativesResponse(ResponseContextAbstract $context): DictionaryResponse;
91
92
    /**
93
     * Create request context for get-translate-alternatives request
94
     *
95
     * @param string   $text
96
     * @param Language $languageTo
97
     * @param Language $languageFrom
98
     *
99
     * @return RequestContext
100
     */
101
    abstract protected function createGetTranslateAlternativesContext(
102
        string $text,
103
        Language $languageTo,
104
        Language $languageFrom
105
    ): RequestContext;
106
107
    /**
108
     * Process response of get-translate-alternatives request and prepare valid response
109
     *
110
     * @param ResponseContextAbstract $context
111
     *
112
     * @return DictionaryResponse
113
     */
114
    abstract protected function prepareGetTranslateAlternativesResponse(ResponseContextAbstract $context): DictionaryResponse;
115
}
116