Merge pull request #27 from cloudflare/phpmd

Enable PHPMD for src and tests
This commit is contained in:
Junade
2017-10-13 15:23:15 +01:00
committed by GitHub
11 changed files with 64 additions and 35 deletions

View File

@@ -10,6 +10,8 @@ fix:
lint:
php $(HERE)/vendor/bin/php-cs-fixer fix --config=$(HERE)/.php_cs --dry-run
php $(HERE)/vendor/bin/phpmd src/ text cleancode,codesize,controversial,design,naming,unusedcode
php $(HERE)/vendor/bin/phpmd tests/ text cleancode,codesize,controversial,design,naming,unusedcode
test:
php $(HERE)/vendor/bin/phpunit --configuration $(HERE)/phpunit.xml

View File

@@ -159,12 +159,12 @@ class PageRulesActions implements Configurations
]);
}
public function setMinification(bool $html, bool $css, bool $js)
public function setMinification(bool $html, bool $css, bool $javascript)
{
$this->addConfigurationOption("minification", [
'html' => $this->getBoolAsOnOrOff($html),
'css' => $this->getBoolAsOnOrOff($css),
'js' => $this->getBoolAsOnOrOff($js),
'js' => $this->getBoolAsOnOrOff($javascript),
]);
}
@@ -297,9 +297,9 @@ class PageRulesActions implements Configurations
return $this->configs;
}
private function addConfigurationOption($id, array $configuration)
private function addConfigurationOption(string $setting, array $configuration)
{
$configuration['id'] = $id;
$configuration['id'] = $setting;
array_push($this->configs, (object) $configuration);
}

View File

@@ -19,6 +19,17 @@ class DNS implements API
$this->adapter = $adapter;
}
/**
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*
* @param string $zoneID
* @param string $type
* @param string $name
* @param string $content
* @param int $ttl
* @param bool $proxied
* @return bool
*/
public function addRecord(
string $zoneID,
string $type,

View File

@@ -21,6 +21,16 @@ class PageRules implements API
$this->adapter = $adapter;
}
/**
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*
* @param string $zoneID
* @param PageRulesTargets $target
* @param PageRulesActions $actions
* @param bool $active
* @param int|null $priority
* @return bool
*/
public function createPageRule(
string $zoneID,
PageRulesTargets $target,

View File

@@ -43,7 +43,7 @@ class UARules implements API
string $zoneID,
string $mode,
\Cloudflare\API\Configurations\Configurations $configuration,
string $id = null,
string $ruleID = null,
string $description = null
): bool {
$options = [
@@ -51,8 +51,8 @@ class UARules implements API
'configurations' => $configuration->getArray()
];
if ($id !== null) {
$options['id'] = $id;
if ($ruleID !== null) {
$options['id'] = $ruleID;
}
if ($description !== null) {

View File

@@ -43,7 +43,7 @@ class ZoneLockdown implements API
string $zoneID,
array $urls,
\Cloudflare\API\Configurations\ZoneLockdown $configuration,
string $id = null,
string $lockdownID = null,
string $description = null
): bool {
$options = [
@@ -51,8 +51,8 @@ class ZoneLockdown implements API
'configurations' => $configuration->getArray()
];
if ($id !== null) {
$options['id'] = $id;
if ($lockdownID !== null) {
$options['id'] = $lockdownID;
}
if ($description !== null) {

View File

@@ -19,6 +19,14 @@ class Zones implements API
$this->adapter = $adapter;
}
/**
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*
* @param string $name
* @param bool $jumpstart
* @param string $organizationID
* @return \stdClass
*/
public function addZone(string $name, bool $jumpstart = false, string $organizationID = ''): \stdClass
{
$options = [

View File

@@ -133,6 +133,6 @@ class GuzzleTest extends TestCase
public function testNotFound()
{
$this->expectException(\GuzzleHttp\Exception\RequestException::class);
$response = $this->client->get('https://httpbin.org/status/404');
$this->client->get('https://httpbin.org/status/404');
}
}

View File

@@ -34,8 +34,8 @@ class PageRulesTest extends TestCase
])
);
$pr = new \Cloudflare\API\Endpoints\PageRules($mock);
$result = $pr->createPageRule('023e105f4ecef8ad9ca31a8372d0c353', $target, $action, true, 1);
$pageRules = new \Cloudflare\API\Endpoints\PageRules($mock);
$result = $pageRules->createPageRule('023e105f4ecef8ad9ca31a8372d0c353', $target, $action, true, 1);
$this->assertTrue($result);
}
@@ -60,8 +60,8 @@ class PageRulesTest extends TestCase
$this->equalTo([])
);
$pr = new \Cloudflare\API\Endpoints\PageRules($mock);
$pr->listPageRules('023e105f4ecef8ad9ca31a8372d0c353', 'active', 'status', 'desc', 'all');
$pageRules = new \Cloudflare\API\Endpoints\PageRules($mock);
$pageRules->listPageRules('023e105f4ecef8ad9ca31a8372d0c353', 'active', 'status', 'desc', 'all');
}
public function testGetPageRuleDetails()
@@ -78,8 +78,8 @@ class PageRulesTest extends TestCase
$this->equalTo([])
);
$pr = new \Cloudflare\API\Endpoints\PageRules($mock);
$pr->getPageRuleDetails('023e105f4ecef8ad9ca31a8372d0c353', '9a7806061c88ada191ed06f989cc3dac');
$pageRules = new \Cloudflare\API\Endpoints\PageRules($mock);
$pageRules->getPageRuleDetails('023e105f4ecef8ad9ca31a8372d0c353', '9a7806061c88ada191ed06f989cc3dac');
}
public function testUpdatePageRule()
@@ -106,8 +106,8 @@ class PageRulesTest extends TestCase
])
);
$pr = new \Cloudflare\API\Endpoints\PageRules($mock);
$result = $pr->updatePageRule('023e105f4ecef8ad9ca31a8372d0c353', $target, $action, true, 1);
$pageRules = new \Cloudflare\API\Endpoints\PageRules($mock);
$result = $pageRules->updatePageRule('023e105f4ecef8ad9ca31a8372d0c353', $target, $action, true, 1);
$this->assertTrue($result);
}
@@ -127,8 +127,8 @@ class PageRulesTest extends TestCase
$this->equalTo([])
);
$pr = new \Cloudflare\API\Endpoints\PageRules($mock);
$result = $pr->deletePageRule('023e105f4ecef8ad9ca31a8372d0c353', '9a7806061c88ada191ed06f989cc3dac');
$pageRules = new \Cloudflare\API\Endpoints\PageRules($mock);
$result = $pageRules->deletePageRule('023e105f4ecef8ad9ca31a8372d0c353', '9a7806061c88ada191ed06f989cc3dac');
$this->assertTrue($result);
}

View File

@@ -6,8 +6,6 @@
* Time: 15:19
*/
use Cloudflare\API\Endpoints\UARules;
class UARulesTest extends TestCase
{
public function testListRules()
@@ -61,8 +59,8 @@ class UARulesTest extends TestCase
])
);
$ld = new \Cloudflare\API\Endpoints\UARules($mock);
$ld->createRule(
$rules = new \Cloudflare\API\Endpoints\UARules($mock);
$rules->createRule(
'023e105f4ecef8ad9ca31a8372d0c353',
'js_challenge',
$config,
@@ -114,8 +112,8 @@ class UARulesTest extends TestCase
])
);
$ld = new \Cloudflare\API\Endpoints\UARules($mock);
$ld->updateRule(
$rules = new \Cloudflare\API\Endpoints\UARules($mock);
$rules->updateRule(
'023e105f4ecef8ad9ca31a8372d0c353',
'372e67954025e0ba6aaa6d586b9e0b59',
'js_challenge',
@@ -139,7 +137,7 @@ class UARulesTest extends TestCase
$this->equalTo([])
);
$ld = new \Cloudflare\API\Endpoints\UARules($mock);
$ld->deleteRule('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59');
$rules = new \Cloudflare\API\Endpoints\UARules($mock);
$rules->deleteRule('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59');
}
}

View File

@@ -59,8 +59,8 @@ class ZoneLockdownTest extends TestCase
])
);
$ld = new \Cloudflare\API\Endpoints\ZoneLockdown($mock);
$ld->createLockdown(
$zoneLockdown = new \Cloudflare\API\Endpoints\ZoneLockdown($mock);
$zoneLockdown->createLockdown(
'023e105f4ecef8ad9ca31a8372d0c353',
["api.mysite.com/some/endpoint*"],
$config,
@@ -112,8 +112,8 @@ class ZoneLockdownTest extends TestCase
])
);
$ld = new \Cloudflare\API\Endpoints\ZoneLockdown($mock);
$ld->updateLockdown(
$zoneLockdown = new \Cloudflare\API\Endpoints\ZoneLockdown($mock);
$zoneLockdown->updateLockdown(
'023e105f4ecef8ad9ca31a8372d0c353',
'372e67954025e0ba6aaa6d586b9e0b59',
["api.mysite.com/some/endpoint*"],
@@ -140,7 +140,7 @@ class ZoneLockdownTest extends TestCase
$this->equalTo([])
);
$ld = new \Cloudflare\API\Endpoints\ZoneLockdown($mock);
$ld->deleteLockdown('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59');
$zoneLockdown = new \Cloudflare\API\Endpoints\ZoneLockdown($mock);
$zoneLockdown->deleteLockdown('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59');
}
}