@@ -188,7 +188,7 @@ public function languages()
188
188
* @return array
189
189
* @throws DeepLException
190
190
*
191
- * @SuppressWarnings(PHPMD.UnusedParameters )
191
+ * @SuppressWarnings(PHPMD.ExcessiveParameterList )
192
192
*/
193
193
public function translate (
194
194
$ text ,
@@ -206,14 +206,20 @@ public function translate(
206
206
if (is_array ($ tagHandling )) {
207
207
throw new \InvalidArgumentException ('$tagHandling must be of type String in V2 of DeepLLibrary ' );
208
208
}
209
- $ paramsArray = array ();
210
- $ reflection = new ReflectionMethod ('Babymarkt\DeepL\DeepL ' , 'translate ' );
209
+ $ paramsArray = array (
210
+ 'text ' => $ text ,
211
+ 'source_lang ' => $ sourceLang ,
212
+ 'target_lang ' => $ targetLang ,
213
+ 'splitting_tags ' => $ splittingTags ,
214
+ 'non_splitting_tags ' => $ nonSplittingTags ,
215
+ 'ignore_tags ' => $ ignoreTags ,
216
+ 'tag_handling ' => $ tagHandling ,
217
+ 'formality ' => $ formality ,
218
+ 'split_sentences ' => $ splitSentences ,
219
+ 'preserve_formatting ' => $ preserveFormatting ,
220
+ 'outline_detection ' => $ outlineDetection ,
221
+ );
211
222
212
- foreach ($ reflection ->getParameters () as $ param ) {
213
- $ paramName = $ param ->name ;
214
- $ paraKey = $ this ->camelToSnake ($ paramName );
215
- $ paramsArray [$ paraKey ] = $ $ paramName ;
216
- }
217
223
$ paramsArray = $ this ->removeEmptyParams ($ paramsArray );
218
224
$ url = $ this ->buildBaseUrl ();
219
225
$ body = $ this ->buildQuery ($ paramsArray );
@@ -283,29 +289,4 @@ protected function buildQuery($paramsArray)
283
289
284
290
return $ body ;
285
291
}
286
-
287
-
288
- /**
289
- * @param string $subject
290
- *
291
- * @return string
292
- */
293
- private function camelToSnake ($ subject )
294
- {
295
- if (preg_match ('/[A-Z]/ ' , $ subject ) === 0 ) {
296
- return $ subject ;
297
- }
298
- $ pattern = '/([a-z])([A-Z])/ ' ;
299
- $ snakeString = strtolower (
300
- preg_replace_callback (
301
- $ pattern ,
302
- function ($ match ) {
303
- return $ match [1 ]."_ " .strtolower ($ match [2 ]);
304
- },
305
- $ subject
306
- )
307
- );
308
-
309
- return $ snakeString ;
310
- }
311
292
}
0 commit comments