Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit c771c4e

Browse files
add phpmd
1 parent bd4ffd7 commit c771c4e

File tree

5 files changed

+48
-15
lines changed

5 files changed

+48
-15
lines changed

composer.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
},
2222
"require-dev": {
2323
"php": ">=5.3 <8.0",
24+
"phpmd/phpmd": "2.4.*",
2425
"phpunit/phpunit": "^4.8",
2526
"squizlabs/php_codesniffer": "^2.9"
2627
},
@@ -36,9 +37,15 @@
3637
},
3738
"scripts": {
3839
"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+
]
4047
},
4148
"config": {
4249
"sort-packages": true
4350
}
44-
}
51+
}

phpcs.xml.dist

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2+
23
<ruleset name="babymarkt/deepl-php-lib">
34
<description>The coding standard of deepl-php-lib package</description>
4-
<arg value="p" />
55

6+
<file>src</file>
7+
<file>tests</file>
8+
9+
<arg value="p" />
610
<arg name="colors" />
711
<arg value="s" />
812

phpmd.xml.dist

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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>

src/DeepL.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,9 @@ public function translate(
175175
throw new DeepLException('No translations found.');
176176
} elseif ($translationsCount == 1) {
177177
return $translationsArray['translations'][0]['text'];
178-
} else {
179-
return $translationsArray['translations'];
180178
}
179+
180+
return $translationsArray['translations'];
181181
}
182182

183183
/**
@@ -298,16 +298,16 @@ protected function request($url, $body)
298298

299299
$response = curl_exec($this->curl);
300300

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)) {
308302
throw new DeepLException('There was a cURL Request Error.');
309303
}
310304

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+
311311
$translationsArray = json_decode($response, true);
312312

313313
if (!$translationsArray) {

tests/DeepLTest.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22

33
namespace BabyMarkt\DeepL;
44

5+
use ReflectionClass;
6+
57
/**
68
* Class DeepLTest
79
*
810
* @package BabyMarkt\DeepL
11+
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
912
*/
1013
class DeepLTest extends \PHPUnit_Framework_TestCase
1114
{
@@ -23,7 +26,9 @@ public static function setUpBeforeClass()
2326
{
2427
parent::setUpBeforeClass();
2528

26-
if (($authKey = getenv('DEEPL_AUTH_KEY')) === false) {
29+
$authKey = getenv('DEEPL_AUTH_KEY');
30+
31+
if ($authKey === false) {
2732
return;
2833
}
2934

@@ -42,7 +47,7 @@ public static function setUpBeforeClass()
4247
*/
4348
protected static function getMethod($className, $methodName)
4449
{
45-
$class = new \ReflectionClass($className);
50+
$class = new ReflectionClass($className);
4651
$method = $class->getMethod($methodName);
4752
$method->setAccessible(true);
4853

@@ -253,6 +258,6 @@ public function testTranslateException()
253258

254259
$this->setExpectedException('\BabyMarkt\DeepL\DeepLException');
255260

256-
$translatedText = $deepl->translate($germanText);
261+
$deepl->translate($germanText);
257262
}
258263
}

0 commit comments

Comments
 (0)