1 | <?php |
||
17 | class MicrosoftTranslator |
||
18 | { |
||
19 | /** |
||
20 | * |
||
21 | */ |
||
22 | const AUTH_URL = 'https://datamarket.accesscontrol.windows.net/v2/OAuth2-13'; |
||
23 | |||
24 | /** |
||
25 | * |
||
26 | */ |
||
27 | const BASE_URL = 'http://api.microsofttranslator.com/V2/Http.svc/'; |
||
28 | |||
29 | /** |
||
30 | * @var \GuzzleHttp\ClientInterface |
||
31 | */ |
||
32 | private $http; |
||
33 | |||
34 | /** |
||
35 | * @var string |
||
36 | */ |
||
37 | private $scope = 'http://api.microsofttranslator.com'; |
||
38 | |||
39 | /** |
||
40 | * @var string |
||
41 | */ |
||
42 | private $grantType = 'client_credentials'; |
||
43 | |||
44 | /** |
||
45 | * @var string |
||
46 | */ |
||
47 | private $clientId; |
||
48 | |||
49 | /** |
||
50 | * @var string |
||
51 | */ |
||
52 | private $clientSecret; |
||
53 | |||
54 | /** |
||
55 | * @var string |
||
56 | */ |
||
57 | private $accessToken; |
||
58 | |||
59 | /** |
||
60 | * MicrosoftTranslator constructor. |
||
61 | */ |
||
62 | 24 | public function __construct(\GuzzleHttp\ClientInterface $httpClient = null) |
|
70 | |||
71 | /** |
||
72 | * @param $id |
||
73 | * @param $secret |
||
74 | */ |
||
75 | 9 | public function setClient($id, $secret) |
|
80 | |||
81 | /** |
||
82 | * @return mixed |
||
83 | * @throws AuthException |
||
84 | */ |
||
85 | 18 | private function getAccessToken() |
|
108 | |||
109 | 15 | private function createRequest(ApiMethodInterface $method) |
|
126 | |||
127 | /** |
||
128 | * @param ApiMethodInterface $method |
||
129 | * @return mixed |
||
130 | * @throws ArgumentException |
||
131 | * @throws QuotaExceededException |
||
132 | * @throws TranslatorException |
||
133 | */ |
||
134 | 15 | private function execute(ApiMethodInterface $method) |
|
151 | |||
152 | /** |
||
153 | * @param string $message |
||
154 | * @throws ArgumentException |
||
155 | * @throws QuotaExceededException |
||
156 | * @throws TokenExpiredException |
||
157 | * @throws TranslatorException |
||
158 | */ |
||
159 | 12 | private function processError(Response $response) |
|
175 | |||
176 | /** |
||
177 | * @param $text |
||
178 | * @param $to |
||
179 | * @param $from |
||
180 | * @return null|string |
||
181 | */ |
||
182 | 15 | public function translate($text, $to, $from = null) |
|
186 | } |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.