This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree 5 files changed +48
-15
lines changed
5 files changed +48
-15
lines changed Original file line number Diff line number Diff line change 21
21
},
22
22
"require-dev" : {
23
23
"php" : " >=5.3 <8.0" ,
24
+ "phpmd/phpmd" : " 2.4.*" ,
24
25
"phpunit/phpunit" : " ^4.8" ,
25
26
"squizlabs/php_codesniffer" : " ^2.9"
26
27
},
36
37
},
37
38
"scripts" : {
38
39
"test" : " vendor/bin/phpunit" ,
39
- "cs" : " vendor/bin/phpcs src tests"
40
+ "cs" : " vendor/bin/phpcs" ,
41
+ "md" : " vendor/bin/phpmd src,tests text phpmd.xml.dist" ,
42
+ "test:full" : [
43
+ " composer test" ,
44
+ " composer cs" ,
45
+ " composer md"
46
+ ]
40
47
},
41
48
"config" : {
42
49
"sort-packages" : true
43
50
}
44
- }
51
+ }
Original file line number Diff line number Diff line change 1
1
<?xml version =" 1.0" encoding =" UTF-8" ?>
2
+
2
3
<ruleset name =" babymarkt/deepl-php-lib" >
3
4
<description >The coding standard of deepl-php-lib package</description >
4
- <arg value =" p" />
5
5
6
+ <file >src</file >
7
+ <file >tests</file >
8
+
9
+ <arg value =" p" />
6
10
<arg name =" colors" />
7
11
<arg value =" s" />
8
12
Original file line number Diff line number Diff line change
1
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2
+
3
+ <ruleset name =" deepl-php-lib ruleset"
4
+ xmlns =" http://pmd.sf.net/ruleset/1.0.0"
5
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
6
+ xsi : schemaLocation =" http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
7
+ xsi : noNamespaceSchemaLocation =" http://pmd.sf.net/ruleset_xml_schema.xsd"
8
+ >
9
+ <description >PHPMD Rules for deepl-php-lib</description >
10
+
11
+ <rule ref =" rulesets/cleancode.xml" />
12
+ <rule ref =" rulesets/codesize.xml" />
13
+ <rule ref =" rulesets/controversial.xml" />
14
+ <rule ref =" rulesets/design.xml" />
15
+ <rule ref =" rulesets/naming.xml" />
16
+ <rule ref =" rulesets/unusedcode.xml" />
17
+ </ruleset >
Original file line number Diff line number Diff line change @@ -175,9 +175,9 @@ public function translate(
175
175
throw new DeepLException ('No translations found. ' );
176
176
} elseif ($ translationsCount == 1 ) {
177
177
return $ translationsArray ['translations ' ][0 ]['text ' ];
178
- } else {
179
- return $ translationsArray ['translations ' ];
180
178
}
179
+
180
+ return $ translationsArray ['translations ' ];
181
181
}
182
182
183
183
/**
@@ -298,16 +298,16 @@ protected function request($url, $body)
298
298
299
299
$ response = curl_exec ($ this ->curl );
300
300
301
- if (!curl_errno ($ this ->curl )) {
302
- $ httpCode = curl_getinfo ($ this ->curl , CURLINFO_HTTP_CODE );
303
-
304
- if ($ httpCode != 200 && array_key_exists ($ httpCode , $ this ->errorCodes )) {
305
- throw new DeepLException ($ this ->errorCodes [$ httpCode ], $ httpCode );
306
- }
307
- } else {
301
+ if (curl_errno ($ this ->curl )) {
308
302
throw new DeepLException ('There was a cURL Request Error. ' );
309
303
}
310
304
305
+ $ httpCode = curl_getinfo ($ this ->curl , CURLINFO_HTTP_CODE );
306
+
307
+ if ($ httpCode != 200 && array_key_exists ($ httpCode , $ this ->errorCodes )) {
308
+ throw new DeepLException ($ this ->errorCodes [$ httpCode ], $ httpCode );
309
+ }
310
+
311
311
$ translationsArray = json_decode ($ response , true );
312
312
313
313
if (!$ translationsArray ) {
Original file line number Diff line number Diff line change 2
2
3
3
namespace BabyMarkt \DeepL ;
4
4
5
+ use ReflectionClass ;
6
+
5
7
/**
6
8
* Class DeepLTest
7
9
*
8
10
* @package BabyMarkt\DeepL
11
+ * @SuppressWarnings(PHPMD.TooManyPublicMethods)
9
12
*/
10
13
class DeepLTest extends \PHPUnit_Framework_TestCase
11
14
{
@@ -23,7 +26,9 @@ public static function setUpBeforeClass()
23
26
{
24
27
parent ::setUpBeforeClass ();
25
28
26
- if (($ authKey = getenv ('DEEPL_AUTH_KEY ' )) === false ) {
29
+ $ authKey = getenv ('DEEPL_AUTH_KEY ' );
30
+
31
+ if ($ authKey === false ) {
27
32
return ;
28
33
}
29
34
@@ -42,7 +47,7 @@ public static function setUpBeforeClass()
42
47
*/
43
48
protected static function getMethod ($ className , $ methodName )
44
49
{
45
- $ class = new \ ReflectionClass ($ className );
50
+ $ class = new ReflectionClass ($ className );
46
51
$ method = $ class ->getMethod ($ methodName );
47
52
$ method ->setAccessible (true );
48
53
@@ -253,6 +258,6 @@ public function testTranslateException()
253
258
254
259
$ this ->setExpectedException ('\BabyMarkt\DeepL\DeepLException ' );
255
260
256
- $ translatedText = $ deepl ->translate ($ germanText );
261
+ $ deepl ->translate ($ germanText );
257
262
}
258
263
}
You can’t perform that action at this time.
0 commit comments