From 0920fc48b2b3e46c98afea43892c0e8a9892a798 Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Tue, 21 Nov 2017 17:25:41 +0100 Subject: [PATCH 01/17] Remove unnecessary double quotes --- src/Adapter/Guzzle.php | 4 +- src/Configurations/PageRulesActions.php | 86 ++++++++++---------- src/Configurations/PageRulesTargets.php | 2 +- src/Configurations/UARules.php | 2 +- src/Configurations/ZoneLockdown.php | 4 +- src/Endpoints/DNS.php | 12 +-- src/Endpoints/Railgun.php | 2 +- src/Endpoints/User.php | 2 +- src/Endpoints/WAF.php | 18 ++-- src/Endpoints/Zones.php | 26 +++--- tests/Adapter/GuzzleTest.php | 22 ++--- tests/Auth/UserServiceKeyTest.php | 2 +- tests/Configurations/PageRulesTargetTest.php | 4 +- tests/Endpoints/DNSTest.php | 16 ++-- tests/Endpoints/IPsTest.php | 4 +- tests/Endpoints/RailgunTest.php | 16 ++-- tests/Endpoints/UARulesTest.php | 8 +- tests/Endpoints/UserTest.php | 14 ++-- tests/Endpoints/WAFTest.php | 36 ++++---- tests/Endpoints/ZoneLockdownTest.php | 16 ++-- tests/Endpoints/ZonesTest.php | 36 ++++---- 21 files changed, 166 insertions(+), 166 deletions(-) diff --git a/src/Adapter/Guzzle.php b/src/Adapter/Guzzle.php index bdbddcd..03dc868 100644 --- a/src/Adapter/Guzzle.php +++ b/src/Adapter/Guzzle.php @@ -21,7 +21,7 @@ class Guzzle implements Adapter public function __construct(Auth $auth, String $baseURI = null) { if ($baseURI === null) { - $baseURI = "https://api.cloudflare.com/client/v4/"; + $baseURI = 'https://api.cloudflare.com/client/v4/'; } $headers = $auth->getHeaders(); @@ -128,7 +128,7 @@ class Guzzle implements Adapter } if (isset($json->success) && ($json->success === false)) { - throw new ResponseException("Request was unsuccessful."); + throw new ResponseException('Request was unsuccessful.'); } } } diff --git a/src/Configurations/PageRulesActions.php b/src/Configurations/PageRulesActions.php index c52ddc1..9eecc7e 100644 --- a/src/Configurations/PageRulesActions.php +++ b/src/Configurations/PageRulesActions.php @@ -14,28 +14,28 @@ class PageRulesActions implements Configurations public function setAlwaysOnline(bool $active) { - $this->addConfigurationOption("always_online", [ + $this->addConfigurationOption('always_online', [ 'value' => $this->getBoolAsOnOrOff($active) ]); } public function setAlwaysUseHTTPS(bool $active) { - $this->addConfigurationOption("always_use_https", [ + $this->addConfigurationOption('always_use_https', [ 'value' => $this->getBoolAsOnOrOff($active) ]); } public function setBrowserCacheTTL(int $ttl) { - $this->addConfigurationOption("browser_cache_ttl", [ + $this->addConfigurationOption('browser_cache_ttl', [ 'value' => $ttl ]); } public function setBrowserIntegrityCheck(bool $active) { - $this->addConfigurationOption("browser_check", [ + $this->addConfigurationOption('browser_check', [ 'value' => $this->getBoolAsOnOrOff($active) ]); } @@ -43,35 +43,35 @@ class PageRulesActions implements Configurations public function setBypassCacheOnCookie(string $value) { if (preg_match('/^([a-zA-Z0-9\.=|_*-]+)$/i', $value) < 1) { - throw new ConfigurationsException("Invalid cookie string."); + throw new ConfigurationsException('Invalid cookie string.'); } - $this->addConfigurationOption("bypass_cache_on_cookie", [ + $this->addConfigurationOption('bypass_cache_on_cookie', [ 'value' => $value ]); } public function setCacheByDeviceType(bool $active) { - $this->addConfigurationOption("cache_by_device_type", [ + $this->addConfigurationOption('cache_by_device_type', [ 'value' => $this->getBoolAsOnOrOff($active) ]); } public function setCacheKey(string $value) { - $this->addConfigurationOption("cache_key", [ + $this->addConfigurationOption('cache_key', [ 'value' => $value ]); } public function setCacheLevel(string $value) { - if (!in_array($value, ["bypass", "basic", "simplified", "aggressive", "cache_everything"])) { - throw new ConfigurationsException("Invalid cache level"); + if (!in_array($value, ['bypass', 'basic', 'simplified', 'aggressive', 'cache_everything'])) { + throw new ConfigurationsException('Invalid cache level'); } - $this->addConfigurationOption("cache_level", [ + $this->addConfigurationOption('cache_level', [ 'value' => $value ]); } @@ -79,31 +79,31 @@ class PageRulesActions implements Configurations public function setCacheOnCookie(string $value) { if (preg_match('/^([a-zA-Z0-9\.=|_*-]+)$/i', $value) < 1) { - throw new ConfigurationsException("Invalid cookie string."); + throw new ConfigurationsException('Invalid cookie string.'); } - $this->addConfigurationOption("cache_on_cookie", [ + $this->addConfigurationOption('cache_on_cookie', [ 'value' => $value ]); } public function setDisableApps(bool $active) { - $this->addConfigurationOption("disable_apps", [ + $this->addConfigurationOption('disable_apps', [ 'value' => $this->getBoolAsOnOrOff($active) ]); } public function setDisablePerformance(bool $active) { - $this->addConfigurationOption("disable_performance", [ + $this->addConfigurationOption('disable_performance', [ 'value' => $this->getBoolAsOnOrOff($active) ]); } public function setDisableSecurity(bool $active) { - $this->addConfigurationOption("disable_security", [ + $this->addConfigurationOption('disable_security', [ 'value' => $this->getBoolAsOnOrOff($active) ]); } @@ -111,17 +111,17 @@ class PageRulesActions implements Configurations public function setEdgeCacheTTL(int $value) { if ($value > 2419200) { - throw new ConfigurationsException("Edge Cache TTL too high."); + throw new ConfigurationsException('Edge Cache TTL too high.'); } - $this->addConfigurationOption("edge_cache_ttl", [ + $this->addConfigurationOption('edge_cache_ttl', [ 'value' => $value ]); } public function setEmailObfuscation(bool $active) { - $this->addConfigurationOption("disable_security", [ + $this->addConfigurationOption('disable_security', [ 'value' => $this->getBoolAsOnOrOff($active) ]); } @@ -132,7 +132,7 @@ class PageRulesActions implements Configurations throw new ConfigurationsException('Status Codes can only be 301 or 302.'); } - $this->addConfigurationOption("forwarding_url", [ + $this->addConfigurationOption('forwarding_url', [ 'status_code' => $statusCode, 'url' => $forwardingUrl, ]); @@ -140,28 +140,28 @@ class PageRulesActions implements Configurations public function setHostHeaderOverride(bool $active) { - $this->addConfigurationOption("host_header_override", [ + $this->addConfigurationOption('host_header_override', [ 'value' => $this->getBoolAsOnOrOff($active) ]); } public function setHotlinkProtection(bool $active) { - $this->addConfigurationOption("hotlink_protection", [ + $this->addConfigurationOption('hotlink_protection', [ 'value' => $this->getBoolAsOnOrOff($active) ]); } public function setIPGeoLocationHeader(bool $active) { - $this->addConfigurationOption("ip_geolocation", [ + $this->addConfigurationOption('ip_geolocation', [ 'value' => $this->getBoolAsOnOrOff($active) ]); } public function setMinification(bool $html, bool $css, bool $javascript) { - $this->addConfigurationOption("minification", [ + $this->addConfigurationOption('minification', [ 'html' => $this->getBoolAsOnOrOff($html), 'css' => $this->getBoolAsOnOrOff($css), 'js' => $this->getBoolAsOnOrOff($javascript), @@ -170,124 +170,124 @@ class PageRulesActions implements Configurations public function setMirage(bool $active) { - $this->addConfigurationOption("mirage", [ + $this->addConfigurationOption('mirage', [ 'value' => $this->getBoolAsOnOrOff($active) ]); } public function setOriginErrorPagePassthru(bool $active) { - $this->addConfigurationOption("origin_error_page_pass_thru", [ + $this->addConfigurationOption('origin_error_page_pass_thru', [ 'value' => $this->getBoolAsOnOrOff($active) ]); } public function setQueryStringSort(bool $active) { - $this->addConfigurationOption("sort_query_string_for_cache", [ + $this->addConfigurationOption('sort_query_string_for_cache', [ 'value' => $this->getBoolAsOnOrOff($active) ]); } public function setDisableRailgun(bool $active) { - $this->addConfigurationOption("disable_railgun", [ + $this->addConfigurationOption('disable_railgun', [ 'value' => $this->getBoolAsOnOrOff($active) ]); } public function setResolveOverride(bool $value) { - $this->addConfigurationOption("resolve_override", [ + $this->addConfigurationOption('resolve_override', [ 'value' => $value ]); } public function setRespectStrongEtag(bool $active) { - $this->addConfigurationOption("respect_strong_etag", [ + $this->addConfigurationOption('respect_strong_etag', [ 'value' => $this->getBoolAsOnOrOff($active) ]); } public function setResponseBuffering(bool $active) { - $this->addConfigurationOption("response_buffering", [ + $this->addConfigurationOption('response_buffering', [ 'value' => $this->getBoolAsOnOrOff($active) ]); } public function setRocketLoader(string $value) { - if (!in_array($value, ["off", "manual", "automatic"])) { + if (!in_array($value, ['off', 'manual', 'automatic'])) { throw new ConfigurationsException('Rocket Loader can only be off, automatic, or manual.'); } - $this->addConfigurationOption("rocket_loader", [ + $this->addConfigurationOption('rocket_loader', [ 'value' => $value ]); } public function setSecurityLevel(string $value) { - if (!in_array($value, ["off", "essentially_off", "low", "medium", "high", "under_attack"])) { + if (!in_array($value, ['off', 'essentially_off', 'low', 'medium', 'high', 'under_attack'])) { throw new ConfigurationsException('Can only be set to off, essentially_off, low, medium, high or under_attack.'); } - $this->addConfigurationOption("security_level", [ + $this->addConfigurationOption('security_level', [ 'value' => $value ]); } public function setServerSideExcludes(bool $active) { - $this->addConfigurationOption("server_side_exclude", [ + $this->addConfigurationOption('server_side_exclude', [ 'value' => $this->getBoolAsOnOrOff($active) ]); } public function setSmartErrors(bool $active) { - $this->addConfigurationOption("smart_errors", [ + $this->addConfigurationOption('smart_errors', [ 'value' => $this->getBoolAsOnOrOff($active) ]); } public function setSSL(string $value) { - if (!in_array($value, ["off", "flexible", "full", "strict", "origin_pull"])) { + if (!in_array($value, ['off', 'flexible', 'full', 'strict', 'origin_pull'])) { throw new ConfigurationsException('Can only be set to off, flexible, full, strict, origin_pull.'); } - $this->addConfigurationOption("smart_errors", [ + $this->addConfigurationOption('smart_errors', [ 'value' => $value ]); } public function setTrueClientIpHeader(bool $active) { - $this->addConfigurationOption("true_client_ip_header", [ + $this->addConfigurationOption('true_client_ip_header', [ 'value' => $this->getBoolAsOnOrOff($active) ]); } public function setWAF(bool $active) { - $this->addConfigurationOption("waf", [ + $this->addConfigurationOption('waf', [ 'value' => $this->getBoolAsOnOrOff($active) ]); } public function setAutomatedHTTPSRewrites(bool $active) { - $this->addConfigurationOption("automatic_https_rewrites", [ + $this->addConfigurationOption('automatic_https_rewrites', [ 'value' => $this->getBoolAsOnOrOff($active) ]); } public function setOpportunisticEncryption(bool $active) { - $this->addConfigurationOption("opportunistic_encryption", [ + $this->addConfigurationOption('opportunistic_encryption', [ 'value' => $this->getBoolAsOnOrOff($active) ]); } diff --git a/src/Configurations/PageRulesTargets.php b/src/Configurations/PageRulesTargets.php index 82d9777..b7e8d26 100644 --- a/src/Configurations/PageRulesTargets.php +++ b/src/Configurations/PageRulesTargets.php @@ -17,7 +17,7 @@ class PageRulesTargets implements Configurations $target = new \stdClass(); $target->target = 'url'; $target->constraint = new \stdClass(); - $target->constraint->operator = "matches"; + $target->constraint->operator = 'matches'; $target->constraint->value = $queryUrl; $this->targets = [$target]; diff --git a/src/Configurations/UARules.php b/src/Configurations/UARules.php index 3b9fe62..a4141f6 100644 --- a/src/Configurations/UARules.php +++ b/src/Configurations/UARules.php @@ -15,7 +15,7 @@ class UARules implements Configurations public function addUA(string $value) { $object = new \stdClass(); - $object->target = "ua"; + $object->target = 'ua'; $object->value = $value; array_push($this->configs, $object); diff --git a/src/Configurations/ZoneLockdown.php b/src/Configurations/ZoneLockdown.php index 4544215..f6eee38 100644 --- a/src/Configurations/ZoneLockdown.php +++ b/src/Configurations/ZoneLockdown.php @@ -15,7 +15,7 @@ class ZoneLockdown implements Configurations public function addIP(string $value) { $object = new \stdClass(); - $object->target = "ip"; + $object->target = 'ip'; $object->value = $value; array_push($this->configs, $object); @@ -24,7 +24,7 @@ class ZoneLockdown implements Configurations public function addIPRange(string $value) { $object = new \stdClass(); - $object->target = "ip_range"; + $object->target = 'ip_range'; $object->value = $value; array_push($this->configs, $object); diff --git a/src/Endpoints/DNS.php b/src/Endpoints/DNS.php index ff4b5bf..b3c0838 100644 --- a/src/Endpoints/DNS.php +++ b/src/Endpoints/DNS.php @@ -62,14 +62,14 @@ class DNS implements API public function listRecords( string $zoneID, - string $type = "", - string $name = "", - string $content = "", + string $type = '', + string $name = '', + string $content = '', int $page = 1, int $perPage = 20, - string $order = "", - string $direction = "", - string $match = "all" + string $order = '', + string $direction = '', + string $match = 'all' ): \stdClass { $query = [ 'page' => $page, diff --git a/src/Endpoints/Railgun.php b/src/Endpoints/Railgun.php index ec31028..1d4bccd 100644 --- a/src/Endpoints/Railgun.php +++ b/src/Endpoints/Railgun.php @@ -35,7 +35,7 @@ class Railgun implements API public function list( int $page = 1, int $perPage = 20, - string $direction = "" + string $direction = '' ): \stdClass { $query = [ 'page' => $page, diff --git a/src/Endpoints/User.php b/src/Endpoints/User.php index 1be88ff..a06c720 100644 --- a/src/Endpoints/User.php +++ b/src/Endpoints/User.php @@ -37,7 +37,7 @@ class User implements API public function updateUserDetails(array $details): \stdClass { - $response = $this->adapter->patch("user", [], $details); + $response = $this->adapter->patch('user', [], $details); return json_decode($response->getBody()); } } diff --git a/src/Endpoints/WAF.php b/src/Endpoints/WAF.php index ec69fb9..5cd6bef 100644 --- a/src/Endpoints/WAF.php +++ b/src/Endpoints/WAF.php @@ -23,9 +23,9 @@ class WAF implements \Cloudflare\API\Endpoints\API string $zoneID, int $page = 1, int $perPage = 20, - string $order = "", - string $direction = "", - string $match = "all" + string $order = '', + string $direction = '', + string $match = 'all' ): \stdClass { $query = [ 'page' => $page, @@ -67,9 +67,9 @@ class WAF implements \Cloudflare\API\Endpoints\API string $packageID, int $page = 1, int $perPage = 20, - string $order = "", - string $direction = "", - string $match = "all" + string $order = '', + string $direction = '', + string $match = 'all' ): \stdClass { $query = [ 'page' => $page, @@ -134,9 +134,9 @@ class WAF implements \Cloudflare\API\Endpoints\API string $packageID, int $page = 1, int $perPage = 20, - string $order = "", - string $direction = "", - string $match = "all" + string $order = '', + string $direction = '', + string $match = 'all' ): \stdClass { $query = [ 'page' => $page, diff --git a/src/Endpoints/Zones.php b/src/Endpoints/Zones.php index fca2673..ce9258b 100644 --- a/src/Endpoints/Zones.php +++ b/src/Endpoints/Zones.php @@ -37,7 +37,7 @@ class Zones implements API if (!empty($organizationID)) { $organization = new \stdClass(); $organization->id = $organizationID; - $options["organization"] = $organization; + $options['organization'] = $organization; } $user = $this->adapter->post('zones', [], $options); @@ -58,13 +58,13 @@ class Zones implements API } public function listZones( - string $name = "", - string $status = "", + string $name = '', + string $status = '', int $page = 1, int $perPage = 20, - string $order = "", - string $direction = "", - string $match = "all" + string $order = '', + string $direction = '', + string $match = 'all' ): \stdClass { $query = [ 'page' => $page, @@ -98,12 +98,12 @@ class Zones implements API return $result; } - public function getZoneID(string $name = ""): string + public function getZoneID(string $name = ''): string { $zones = $this->listZones($name); if (sizeof($zones->result) < 1) { - throw new EndpointException("Could not find zones with specified name."); + throw new EndpointException('Could not find zones with specified name.'); } return $zones->result[0]->id; @@ -118,9 +118,9 @@ class Zones implements API * @param bool $continuous * @return \stdClass */ - public function getAnalyticsDashboard(string $zoneID, string $since = "-10080", string $until = "0", bool $continuous = true): \stdClass + public function getAnalyticsDashboard(string $zoneID, string $since = '-10080', string $until = '0', bool $continuous = true): \stdClass { - $response = $this->adapter->get('zones/' . $zoneID . '/analytics/dashboard', [], ["since" => $since, "until" => $until, "continuous" => $continuous]); + $response = $this->adapter->get('zones/' . $zoneID . '/analytics/dashboard', [], ['since' => $since, 'until' => $until, 'continuous' => $continuous]); return json_decode($response->getBody())->result; } @@ -134,7 +134,7 @@ class Zones implements API */ public function changeDevelopmentMode(string $zoneID, bool $enable = false): bool { - $response = $this->adapter->patch('zones/' . $zoneID . '/settings/development_mode', [], ["value" => ($enable ? "on" : "off")]); + $response = $this->adapter->patch('zones/' . $zoneID . '/settings/development_mode', [], ['value' => ($enable ? 'on' : 'off')]); $body = json_decode($response->getBody()); @@ -153,7 +153,7 @@ class Zones implements API */ public function cachePurgeEverything(string $zoneID): bool { - $user = $this->adapter->delete('zones/' . $zoneID . '/purge_cache', [], ["purge_everything" => true]); + $user = $this->adapter->delete('zones/' . $zoneID . '/purge_cache', [], ['purge_everything' => true]); $body = json_decode($user->getBody()); @@ -167,7 +167,7 @@ class Zones implements API public function cachePurge(string $zoneID, array $files = null, array $tags = null): bool { if (is_null($files) && is_null($tags)) { - throw new EndpointException("No files or tags to purge."); + throw new EndpointException('No files or tags to purge.'); } $options = [ diff --git a/tests/Adapter/GuzzleTest.php b/tests/Adapter/GuzzleTest.php index de97374..efbe2b0 100644 --- a/tests/Adapter/GuzzleTest.php +++ b/tests/Adapter/GuzzleTest.php @@ -29,14 +29,14 @@ class GuzzleTest extends TestCase $response = $this->client->get('https://httpbin.org/get'); $headers = $response->getHeaders(); - $this->assertEquals("application/json", $headers["Content-Type"][0]); + $this->assertEquals('application/json', $headers['Content-Type'][0]); $body = json_decode($response->getBody()); - $this->assertEquals("Test", $body->headers->{"X-Testing"}); + $this->assertEquals('Test', $body->headers->{'X-Testing'}); $response = $this->client->get('https://httpbin.org/get', [], ['X-Another-Test' => 'Test2']); $body = json_decode($response->getBody()); - $this->assertEquals("Test2", $body->headers->{"X-Another-Test"}); + $this->assertEquals('Test2', $body->headers->{'X-Another-Test'}); } public function testPost() @@ -44,10 +44,10 @@ class GuzzleTest extends TestCase $response = $this->client->post('https://httpbin.org/post', [], ['X-Post-Test' => 'Testing a POST request.']); $headers = $response->getHeaders(); - $this->assertEquals("application/json", $headers["Content-Type"][0]); + $this->assertEquals('application/json', $headers['Content-Type'][0]); $body = json_decode($response->getBody()); - $this->assertEquals("Testing a POST request.", $body->json->{"X-Post-Test"}); + $this->assertEquals('Testing a POST request.', $body->json->{'X-Post-Test'}); } public function testPut() @@ -55,10 +55,10 @@ class GuzzleTest extends TestCase $response = $this->client->put('https://httpbin.org/put', [], ['X-Put-Test' => 'Testing a PUT request.']); $headers = $response->getHeaders(); - $this->assertEquals("application/json", $headers["Content-Type"][0]); + $this->assertEquals('application/json', $headers['Content-Type'][0]); $body = json_decode($response->getBody()); - $this->assertEquals("Testing a PUT request.", $body->json->{"X-Put-Test"}); + $this->assertEquals('Testing a PUT request.', $body->json->{'X-Put-Test'}); } public function testPatch() @@ -70,10 +70,10 @@ class GuzzleTest extends TestCase ); $headers = $response->getHeaders(); - $this->assertEquals("application/json", $headers["Content-Type"][0]); + $this->assertEquals('application/json', $headers['Content-Type'][0]); $body = json_decode($response->getBody()); - $this->assertEquals("Testing a PATCH request.", $body->json->{"X-Patch-Test"}); + $this->assertEquals('Testing a PATCH request.', $body->json->{'X-Patch-Test'}); } public function testDelete() @@ -85,10 +85,10 @@ class GuzzleTest extends TestCase ); $headers = $response->getHeaders(); - $this->assertEquals("application/json", $headers["Content-Type"][0]); + $this->assertEquals('application/json', $headers['Content-Type'][0]); $body = json_decode($response->getBody()); - $this->assertEquals("Testing a DELETE request.", $body->json->{"X-Delete-Test"}); + $this->assertEquals('Testing a DELETE request.', $body->json->{'X-Delete-Test'}); } public function testErrors() diff --git a/tests/Auth/UserServiceKeyTest.php b/tests/Auth/UserServiceKeyTest.php index e833e99..48b1893 100644 --- a/tests/Auth/UserServiceKeyTest.php +++ b/tests/Auth/UserServiceKeyTest.php @@ -9,7 +9,7 @@ class UserServiceKeyTest extends TestCase { public function testGetHeaders() { - $auth = new \Cloudflare\API\Auth\UserServiceKey("v1.0-e24fd090c02efcfecb4de8f4ff246fd5c75b48946fdf0ce26c59f91d0d90797b-cfa33fe60e8e34073c149323454383fc9005d25c9b4c502c2f063457ef65322eade065975001a0b4b4c591c5e1bd36a6e8f7e2d4fa8a9ec01c64c041e99530c2-07b9efe0acd78c82c8d9c690aacb8656d81c369246d7f996a205fe3c18e9254a"); + $auth = new \Cloudflare\API\Auth\UserServiceKey('v1.0-e24fd090c02efcfecb4de8f4ff246fd5c75b48946fdf0ce26c59f91d0d90797b-cfa33fe60e8e34073c149323454383fc9005d25c9b4c502c2f063457ef65322eade065975001a0b4b4c591c5e1bd36a6e8f7e2d4fa8a9ec01c64c041e99530c2-07b9efe0acd78c82c8d9c690aacb8656d81c369246d7f996a205fe3c18e9254a'); $headers = $auth->getHeaders(); $this->assertArrayHasKey('X-Auth-User-Service-Key', $headers); diff --git a/tests/Configurations/PageRulesTargetTest.php b/tests/Configurations/PageRulesTargetTest.php index 8958372..dbae7aa 100644 --- a/tests/Configurations/PageRulesTargetTest.php +++ b/tests/Configurations/PageRulesTargetTest.php @@ -16,7 +16,7 @@ class PageRulesTargetTest extends TestCase $array = $targets->getArray(); $this->assertEquals(1, sizeof($array)); - $this->assertEquals("junade.com/*", $array[0]->constraint->value); - $this->assertEquals("matches", $array[0]->constraint->operator); + $this->assertEquals('junade.com/*', $array[0]->constraint->value); + $this->assertEquals('matches', $array[0]->constraint->operator); } } diff --git a/tests/Endpoints/DNSTest.php b/tests/Endpoints/DNSTest.php index 66eb9d9..ceef67d 100644 --- a/tests/Endpoints/DNSTest.php +++ b/tests/Endpoints/DNSTest.php @@ -57,12 +57,12 @@ class DNSTest extends TestCase ); $zones = new \Cloudflare\API\Endpoints\DNS($mock); - $result = $zones->listRecords("023e105f4ecef8ad9ca31a8372d0c353", "A", "example.com", "127.0.0.1", 1, 20, "type", "desc", "all"); + $result = $zones->listRecords('023e105f4ecef8ad9ca31a8372d0c353', 'A', 'example.com', '127.0.0.1', 1, 20, 'type', 'desc', 'all'); $this->assertObjectHasAttribute('result', $result); $this->assertObjectHasAttribute('result_info', $result); - $this->assertEquals("372e67954025e0ba6aaa6d586b9e0b59", $result->result[0]->id); + $this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result->result[0]->id); $this->assertEquals(1, $result->result_info->page); } @@ -81,9 +81,9 @@ class DNSTest extends TestCase ); $dns = new \Cloudflare\API\Endpoints\DNS($mock); - $result = $dns->getRecordDetails("023e105f4ecef8ad9ca31a8372d0c353", "372e67954025e0ba6aaa6d586b9e0b59"); + $result = $dns->getRecordDetails('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59'); - $this->assertEquals("372e67954025e0ba6aaa6d586b9e0b59", $result->id); + $this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result->id); } public function testUpdateDNSRecord() @@ -95,8 +95,8 @@ class DNSTest extends TestCase $details = [ 'type' => 'A', - 'name' => "example.com", - 'content' => "1.2.3.4", + 'name' => 'example.com', + 'content' => '1.2.3.4', 'ttl' => 120, 'proxied' => false, ]; @@ -110,9 +110,9 @@ class DNSTest extends TestCase ); $dns = new \Cloudflare\API\Endpoints\DNS($mock); - $result = $dns->updateRecordDetails("023e105f4ecef8ad9ca31a8372d0c353", "372e67954025e0ba6aaa6d586b9e0b59", $details); + $result = $dns->updateRecordDetails('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59', $details); - $this->assertEquals("372e67954025e0ba6aaa6d586b9e0b59", $result->result->id); + $this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result->result->id); foreach ($details as $property => $value) { $this->assertEquals($result->result->{ $property }, $value); diff --git a/tests/Endpoints/IPsTest.php b/tests/Endpoints/IPsTest.php index c244b64..de81da1 100644 --- a/tests/Endpoints/IPsTest.php +++ b/tests/Endpoints/IPsTest.php @@ -26,7 +26,7 @@ class IPsTest extends TestCase $ips = new \Cloudflare\API\Endpoints\IPs($mock); $ips = $ips->listIPs(); - $this->assertObjectHasAttribute("ipv4_cidrs", $ips); - $this->assertObjectHasAttribute("ipv6_cidrs", $ips); + $this->assertObjectHasAttribute('ipv4_cidrs', $ips); + $this->assertObjectHasAttribute('ipv6_cidrs', $ips); } } diff --git a/tests/Endpoints/RailgunTest.php b/tests/Endpoints/RailgunTest.php index 10726a0..1126a84 100644 --- a/tests/Endpoints/RailgunTest.php +++ b/tests/Endpoints/RailgunTest.php @@ -13,7 +13,7 @@ class RailgunTest extends TestCase public function testcreate() { $details = [ - 'name' => "My Railgun", + 'name' => 'My Railgun', ]; $response = $this->getPsr7JsonResponseForFixture('Endpoints/createRailgun.json'); @@ -59,7 +59,7 @@ class RailgunTest extends TestCase ); $railgun = new \Cloudflare\API\Endpoints\Railgun($mock); - $result = $railgun->list(1, 20, "desc"); + $result = $railgun->list(1, 20, 'desc'); $this->assertObjectHasAttribute('result', $result); $this->assertObjectHasAttribute('result_info', $result); @@ -80,9 +80,9 @@ class RailgunTest extends TestCase ); $railgun = new \Cloudflare\API\Endpoints\Railgun($mock); - $result = $railgun->get("e928d310693a83094309acf9ead50448"); + $result = $railgun->get('e928d310693a83094309acf9ead50448'); - $this->assertEquals("e928d310693a83094309acf9ead50448", $result->id); + $this->assertEquals('e928d310693a83094309acf9ead50448', $result->id); } public function testgetZones() @@ -101,7 +101,7 @@ class RailgunTest extends TestCase ); $railgun = new \Cloudflare\API\Endpoints\Railgun($mock); - $result = $railgun->getZones("e928d310693a83094309acf9ead50448"); + $result = $railgun->getZones('e928d310693a83094309acf9ead50448'); $this->assertObjectHasAttribute('result', $result); $this->assertObjectHasAttribute('result_info', $result); @@ -127,9 +127,9 @@ class RailgunTest extends TestCase ); $waf = new \Cloudflare\API\Endpoints\Railgun($mock); - $result = $waf->update("e928d310693a83094309acf9ead50448", true); + $result = $waf->update('e928d310693a83094309acf9ead50448', true); - $this->assertEquals("e928d310693a83094309acf9ead50448", $result->id); + $this->assertEquals('e928d310693a83094309acf9ead50448', $result->id); } public function testdelete() @@ -148,6 +148,6 @@ class RailgunTest extends TestCase ); $waf = new \Cloudflare\API\Endpoints\Railgun($mock); - $waf->delete("e928d310693a83094309acf9ead50448"); + $waf->delete('e928d310693a83094309acf9ead50448'); } } diff --git a/tests/Endpoints/UARulesTest.php b/tests/Endpoints/UARulesTest.php index 987069a..b8ba884 100644 --- a/tests/Endpoints/UARulesTest.php +++ b/tests/Endpoints/UARulesTest.php @@ -27,12 +27,12 @@ class UARulesTest extends TestCase ); $zones = new \Cloudflare\API\Endpoints\UARules($mock); - $result = $zones->listRules("023e105f4ecef8ad9ca31a8372d0c353", 1, 20); + $result = $zones->listRules('023e105f4ecef8ad9ca31a8372d0c353', 1, 20); $this->assertObjectHasAttribute('result', $result); $this->assertObjectHasAttribute('result_info', $result); - $this->assertEquals("372e67954025e0ba6aaa6d586b9e0b59", $result->result[0]->id); + $this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result->result[0]->id); $this->assertEquals(1, $result->result_info->page); } @@ -84,9 +84,9 @@ class UARulesTest extends TestCase ); $lockdown = new \Cloudflare\API\Endpoints\UARules($mock); - $result = $lockdown->getRuleDetails("023e105f4ecef8ad9ca31a8372d0c353", "372e67954025e0ba6aaa6d586b9e0b59"); + $result = $lockdown->getRuleDetails('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59'); - $this->assertEquals("372e67954025e0ba6aaa6d586b9e0b59", $result->id); + $this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result->id); } public function testUpdateRule() diff --git a/tests/Endpoints/UserTest.php b/tests/Endpoints/UserTest.php index aabe329..819e086 100644 --- a/tests/Endpoints/UserTest.php +++ b/tests/Endpoints/UserTest.php @@ -17,10 +17,10 @@ class UserTest extends TestCase $user = new \Cloudflare\API\Endpoints\User($mock); $details = $user->getUserDetails(); - $this->assertObjectHasAttribute("id", $details); - $this->assertEquals("7c5dae5552338874e5053f2534d2767a", $details->id); - $this->assertObjectHasAttribute("email", $details); - $this->assertEquals("user@example.com", $details->email); + $this->assertObjectHasAttribute('id', $details); + $this->assertEquals('7c5dae5552338874e5053f2534d2767a', $details->id); + $this->assertObjectHasAttribute('email', $details); + $this->assertEquals('user@example.com', $details->email); } public function testGetUserID() @@ -31,7 +31,7 @@ class UserTest extends TestCase $mock->method('get')->willReturn($response); $user = new \Cloudflare\API\Endpoints\User($mock); - $this->assertEquals("7c5dae5552338874e5053f2534d2767a", $user->getUserID()); + $this->assertEquals('7c5dae5552338874e5053f2534d2767a', $user->getUserID()); } public function testGetUserEmail() @@ -44,7 +44,7 @@ class UserTest extends TestCase $mock->expects($this->once())->method('get'); $user = new \Cloudflare\API\Endpoints\User($mock); - $this->assertEquals("user@example.com", $user->getUserEmail()); + $this->assertEquals('user@example.com', $user->getUserEmail()); } public function testUpdateUserDetails() @@ -59,6 +59,6 @@ class UserTest extends TestCase ->with($this->equalTo('user'), $this->equalTo([]), $this->equalTo(['email' => 'user2@example.com'])); $user = new \Cloudflare\API\Endpoints\User($mock); - $user->updateUserDetails(['email' => "user2@example.com"]); + $user->updateUserDetails(['email' => 'user2@example.com']); } } diff --git a/tests/Endpoints/WAFTest.php b/tests/Endpoints/WAFTest.php index 0a31cae..40ae35f 100644 --- a/tests/Endpoints/WAFTest.php +++ b/tests/Endpoints/WAFTest.php @@ -32,12 +32,12 @@ class WAFTest extends TestCase ); $waf = new \Cloudflare\API\Endpoints\WAF($mock); - $result = $waf->getPackages("023e105f4ecef8ad9ca31a8372d0c353", 1, 20, "status", "desc", "all"); + $result = $waf->getPackages('023e105f4ecef8ad9ca31a8372d0c353', 1, 20, 'status', 'desc', 'all'); $this->assertObjectHasAttribute('result', $result); $this->assertObjectHasAttribute('result_info', $result); - $this->assertEquals("a25a9a7e9c00afc1fb2e0245519d725b", $result->result[0]->id); + $this->assertEquals('a25a9a7e9c00afc1fb2e0245519d725b', $result->result[0]->id); $this->assertEquals(1, $result->result_info->page); } @@ -56,9 +56,9 @@ class WAFTest extends TestCase ); $waf = new \Cloudflare\API\Endpoints\WAF($mock); - $result = $waf->getPackageInfo("023e105f4ecef8ad9ca31a8372d0c353", "a25a9a7e9c00afc1fb2e0245519d725b"); + $result = $waf->getPackageInfo('023e105f4ecef8ad9ca31a8372d0c353', 'a25a9a7e9c00afc1fb2e0245519d725b'); - $this->assertEquals("a25a9a7e9c00afc1fb2e0245519d725b", $result->id); + $this->assertEquals('a25a9a7e9c00afc1fb2e0245519d725b', $result->id); } public function testgetRules() @@ -83,12 +83,12 @@ class WAFTest extends TestCase ); $waf = new \Cloudflare\API\Endpoints\WAF($mock); - $result = $waf->getRules("023e105f4ecef8ad9ca31a8372d0c353", "a25a9a7e9c00afc1fb2e0245519d725b", 1, 20, "status", "desc", "all"); + $result = $waf->getRules('023e105f4ecef8ad9ca31a8372d0c353', 'a25a9a7e9c00afc1fb2e0245519d725b', 1, 20, 'status', 'desc', 'all'); $this->assertObjectHasAttribute('result', $result); $this->assertObjectHasAttribute('result_info', $result); - $this->assertEquals("92f17202ed8bd63d69a66b86a49a8f6b", $result->result[0]->id); + $this->assertEquals('92f17202ed8bd63d69a66b86a49a8f6b', $result->result[0]->id); $this->assertEquals(1, $result->result_info->page); } @@ -107,9 +107,9 @@ class WAFTest extends TestCase ); $waf = new \Cloudflare\API\Endpoints\WAF($mock); - $result = $waf->getRuleInfo("023e105f4ecef8ad9ca31a8372d0c353", "a25a9a7e9c00afc1fb2e0245519d725b", "f939de3be84e66e757adcdcb87908023"); + $result = $waf->getRuleInfo('023e105f4ecef8ad9ca31a8372d0c353', 'a25a9a7e9c00afc1fb2e0245519d725b', 'f939de3be84e66e757adcdcb87908023'); - $this->assertEquals("f939de3be84e66e757adcdcb87908023", $result->id); + $this->assertEquals('f939de3be84e66e757adcdcb87908023', $result->id); } public function testupdateRule() @@ -120,7 +120,7 @@ class WAFTest extends TestCase $mock->method('patch')->willReturn($response); $details = [ - 'mode' => "on", + 'mode' => 'on', ]; $mock->expects($this->once()) @@ -132,9 +132,9 @@ class WAFTest extends TestCase ); $waf = new \Cloudflare\API\Endpoints\WAF($mock); - $result = $waf->updateRule("023e105f4ecef8ad9ca31a8372d0c353", "a25a9a7e9c00afc1fb2e0245519d725b", "f939de3be84e66e757adcdcb87908023", "on"); + $result = $waf->updateRule('023e105f4ecef8ad9ca31a8372d0c353', 'a25a9a7e9c00afc1fb2e0245519d725b', 'f939de3be84e66e757adcdcb87908023', 'on'); - $this->assertEquals("f939de3be84e66e757adcdcb87908023", $result->id); + $this->assertEquals('f939de3be84e66e757adcdcb87908023', $result->id); foreach ($details as $property => $value) { $this->assertEquals($result->{ $property }, $value); @@ -163,12 +163,12 @@ class WAFTest extends TestCase ); $waf = new \Cloudflare\API\Endpoints\WAF($mock); - $result = $waf->getGroups("023e105f4ecef8ad9ca31a8372d0c353", "a25a9a7e9c00afc1fb2e0245519d725b", 1, 20, "status", "desc", "all"); + $result = $waf->getGroups('023e105f4ecef8ad9ca31a8372d0c353', 'a25a9a7e9c00afc1fb2e0245519d725b', 1, 20, 'status', 'desc', 'all'); $this->assertObjectHasAttribute('result', $result); $this->assertObjectHasAttribute('result_info', $result); - $this->assertEquals("de677e5818985db1285d0e80225f06e5", $result->result[0]->id); + $this->assertEquals('de677e5818985db1285d0e80225f06e5', $result->result[0]->id); $this->assertEquals(1, $result->result_info->page); } @@ -187,9 +187,9 @@ class WAFTest extends TestCase ); $waf = new \Cloudflare\API\Endpoints\WAF($mock); - $result = $waf->getGroupInfo("023e105f4ecef8ad9ca31a8372d0c353", "a25a9a7e9c00afc1fb2e0245519d725b", "de677e5818985db1285d0e80225f06e5"); + $result = $waf->getGroupInfo('023e105f4ecef8ad9ca31a8372d0c353', 'a25a9a7e9c00afc1fb2e0245519d725b', 'de677e5818985db1285d0e80225f06e5'); - $this->assertEquals("de677e5818985db1285d0e80225f06e5", $result->id); + $this->assertEquals('de677e5818985db1285d0e80225f06e5', $result->id); } public function testupdateGroup() @@ -200,7 +200,7 @@ class WAFTest extends TestCase $mock->method('patch')->willReturn($response); $details = [ - 'mode' => "off", + 'mode' => 'off', ]; $mock->expects($this->once()) @@ -212,9 +212,9 @@ class WAFTest extends TestCase ); $waf = new \Cloudflare\API\Endpoints\WAF($mock); - $result = $waf->updateGroup("023e105f4ecef8ad9ca31a8372d0c353", "a25a9a7e9c00afc1fb2e0245519d725b", "de677e5818985db1285d0e80225f06e5", "off"); + $result = $waf->updateGroup('023e105f4ecef8ad9ca31a8372d0c353', 'a25a9a7e9c00afc1fb2e0245519d725b', 'de677e5818985db1285d0e80225f06e5', 'off'); - $this->assertEquals("de677e5818985db1285d0e80225f06e5", $result->id); + $this->assertEquals('de677e5818985db1285d0e80225f06e5', $result->id); foreach ($details as $property => $value) { $this->assertEquals($result->{ $property }, $value); diff --git a/tests/Endpoints/ZoneLockdownTest.php b/tests/Endpoints/ZoneLockdownTest.php index 066ebef..f534de5 100644 --- a/tests/Endpoints/ZoneLockdownTest.php +++ b/tests/Endpoints/ZoneLockdownTest.php @@ -27,12 +27,12 @@ class ZoneLockdownTest extends TestCase ); $zones = new \Cloudflare\API\Endpoints\ZoneLockdown($mock); - $result = $zones->listLockdowns("023e105f4ecef8ad9ca31a8372d0c353", 1, 20); + $result = $zones->listLockdowns('023e105f4ecef8ad9ca31a8372d0c353', 1, 20); $this->assertObjectHasAttribute('result', $result); $this->assertObjectHasAttribute('result_info', $result); - $this->assertEquals("372e67954025e0ba6aaa6d586b9e0b59", $result->result[0]->id); + $this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result->result[0]->id); $this->assertEquals(1, $result->result_info->page); } @@ -52,7 +52,7 @@ class ZoneLockdownTest extends TestCase $this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns'), $this->equalTo([]), $this->equalTo([ - 'urls' => ["api.mysite.com/some/endpoint*"], + 'urls' => ['api.mysite.com/some/endpoint*'], 'id' => '372e67954025e0ba6aaa6d586b9e0b59', 'description' => 'Restrict access to these endpoints to requests from a known IP address', 'configurations' => $config->getArray(), @@ -62,7 +62,7 @@ class ZoneLockdownTest extends TestCase $zoneLockdown = new \Cloudflare\API\Endpoints\ZoneLockdown($mock); $zoneLockdown->createLockdown( '023e105f4ecef8ad9ca31a8372d0c353', - ["api.mysite.com/some/endpoint*"], + ['api.mysite.com/some/endpoint*'], $config, '372e67954025e0ba6aaa6d586b9e0b59', 'Restrict access to these endpoints to requests from a known IP address' @@ -84,9 +84,9 @@ class ZoneLockdownTest extends TestCase ); $lockdown = new \Cloudflare\API\Endpoints\ZoneLockdown($mock); - $result = $lockdown->getLockdownDetails("023e105f4ecef8ad9ca31a8372d0c353", "372e67954025e0ba6aaa6d586b9e0b59"); + $result = $lockdown->getLockdownDetails('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59'); - $this->assertEquals("372e67954025e0ba6aaa6d586b9e0b59", $result->id); + $this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result->id); } public function testUpdateLockdown() @@ -105,7 +105,7 @@ class ZoneLockdownTest extends TestCase $this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns/372e67954025e0ba6aaa6d586b9e0b59'), $this->equalTo([]), $this->equalTo([ - 'urls' => ["api.mysite.com/some/endpoint*"], + 'urls' => ['api.mysite.com/some/endpoint*'], 'id' => '372e67954025e0ba6aaa6d586b9e0b59', 'description' => 'Restrict access to these endpoints to requests from a known IP address', 'configurations' => $config->getArray(), @@ -116,7 +116,7 @@ class ZoneLockdownTest extends TestCase $zoneLockdown->updateLockdown( '023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59', - ["api.mysite.com/some/endpoint*"], + ['api.mysite.com/some/endpoint*'], $config, 'Restrict access to these endpoints to requests from a known IP address' ); diff --git a/tests/Endpoints/ZonesTest.php b/tests/Endpoints/ZonesTest.php index 7ec0a86..c9ff843 100644 --- a/tests/Endpoints/ZonesTest.php +++ b/tests/Endpoints/ZonesTest.php @@ -24,10 +24,10 @@ class ZonesTest extends TestCase ); $zones = new \Cloudflare\API\Endpoints\Zones($mock); - $result = $zones->addZone("example.com"); + $result = $zones->addZone('example.com'); - $this->assertObjectHasAttribute("id", $result); - $this->assertEquals("023e105f4ecef8ad9ca31a8372d0c353", $result->id); + $this->assertObjectHasAttribute('id', $result); + $this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $result->id); $response = $this->getPsr7JsonResponseForFixture('Endpoints/createPageRule.json'); @@ -35,7 +35,7 @@ class ZonesTest extends TestCase $mock->method('post')->willReturn($response); $org = new stdClass(); - $org->id = "01a7362d577a6c3019a474fd6f485823"; + $org->id = '01a7362d577a6c3019a474fd6f485823'; $mock->expects($this->once()) ->method('post') @@ -46,7 +46,7 @@ class ZonesTest extends TestCase ); $zones = new \Cloudflare\API\Endpoints\Zones($mock); - $zones->addZone("example.com", true, "01a7362d577a6c3019a474fd6f485823"); + $zones->addZone('example.com', true, '01a7362d577a6c3019a474fd6f485823'); } public function testActivationTest() @@ -65,7 +65,7 @@ class ZonesTest extends TestCase ); $zones = new \Cloudflare\API\Endpoints\Zones($mock); - $result = $zones->activationCheck("c2547eb745079dac9320b638f5e225cf483cc5cfdda41"); + $result = $zones->activationCheck('c2547eb745079dac9320b638f5e225cf483cc5cfdda41'); $this->assertTrue($result); } @@ -94,12 +94,12 @@ class ZonesTest extends TestCase ); $zones = new \Cloudflare\API\Endpoints\Zones($mock); - $result = $zones->listZones("example.com", "active", 1, 20, "status", "desc", "all"); + $result = $zones->listZones('example.com', 'active', 1, 20, 'status', 'desc', 'all'); $this->assertObjectHasAttribute('result', $result); $this->assertObjectHasAttribute('result_info', $result); - $this->assertEquals("023e105f4ecef8ad9ca31a8372d0c353", $result->result[0]->id); + $this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $result->result[0]->id); $this->assertEquals(1, $result->result_info->page); } @@ -124,9 +124,9 @@ class ZonesTest extends TestCase ); $zones = new \Cloudflare\API\Endpoints\Zones($mock); - $result = $zones->getZoneID("example.com"); + $result = $zones->getZoneID('example.com'); - $this->assertEquals("023e105f4ecef8ad9ca31a8372d0c353", $result); + $this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $result); } public function testGetAnalyticsDashboard() @@ -141,14 +141,14 @@ class ZonesTest extends TestCase ->with( $this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/analytics/dashboard'), $this->equalTo([]), - $this->equalTo(["since" => "-10080", "until" => "0", "continuous" => true]) + $this->equalTo(['since' => '-10080', 'until' => '0', 'continuous' => true]) ); $zones = new \Cloudflare\API\Endpoints\Zones($mock); - $analytics = $zones->getAnalyticsDashboard("c2547eb745079dac9320b638f5e225cf483cc5cfdda41"); + $analytics = $zones->getAnalyticsDashboard('c2547eb745079dac9320b638f5e225cf483cc5cfdda41'); - $this->assertObjectHasAttribute("since", $analytics->totals); - $this->assertObjectHasAttribute("since", $analytics->timeseries[0]); + $this->assertObjectHasAttribute('since', $analytics->totals); + $this->assertObjectHasAttribute('since', $analytics->timeseries[0]); } public function testChangeDevelopmentMode() @@ -163,11 +163,11 @@ class ZonesTest extends TestCase ->with( $this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/development_mode'), $this->equalTo([]), - $this->equalTo(["value" => "on"]) + $this->equalTo(['value' => 'on']) ); $zones = new \Cloudflare\API\Endpoints\Zones($mock); - $result = $zones->changeDevelopmentMode("c2547eb745079dac9320b638f5e225cf483cc5cfdda41", true); + $result = $zones->changeDevelopmentMode('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', true); $this->assertTrue($result); } @@ -184,11 +184,11 @@ class ZonesTest extends TestCase ->with( $this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/purge_cache'), $this->equalTo([]), - $this->equalTo(["purge_everything" => true]) + $this->equalTo(['purge_everything' => true]) ); $zones = new \Cloudflare\API\Endpoints\Zones($mock); - $result = $zones->cachePurgeEverything("c2547eb745079dac9320b638f5e225cf483cc5cfdda41"); + $result = $zones->cachePurgeEverything('c2547eb745079dac9320b638f5e225cf483cc5cfdda41'); $this->assertTrue($result); } From 7c9ea4874d8fe5bd87d59832896d4b81311f07bc Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Tue, 21 Nov 2017 17:27:47 +0100 Subject: [PATCH 02/17] Shorten the fully qualified class names --- src/Endpoints/UARules.php | 3 ++- src/Endpoints/WAF.php | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Endpoints/UARules.php b/src/Endpoints/UARules.php index 0da89a9..6eb0efb 100644 --- a/src/Endpoints/UARules.php +++ b/src/Endpoints/UARules.php @@ -8,6 +8,7 @@ namespace Cloudflare\API\Endpoints; +use Cloudflare\API\Configurations\Configurations; use Cloudflare\API\Adapter\Adapter; class UARules implements API @@ -42,7 +43,7 @@ class UARules implements API public function createRule( string $zoneID, string $mode, - \Cloudflare\API\Configurations\Configurations $configuration, + Configurations $configuration, string $ruleID = null, string $description = null ): bool { diff --git a/src/Endpoints/WAF.php b/src/Endpoints/WAF.php index 5cd6bef..805c8ab 100644 --- a/src/Endpoints/WAF.php +++ b/src/Endpoints/WAF.php @@ -10,7 +10,7 @@ namespace Cloudflare\API\Endpoints; use Cloudflare\API\Adapter\Adapter; -class WAF implements \Cloudflare\API\Endpoints\API +class WAF implements API { private $adapter; From 4f3f82b1baebee5c79fe2e69320b6ac3d92f95d9 Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Tue, 21 Nov 2017 17:28:47 +0100 Subject: [PATCH 03/17] Remove redundant parentheses --- src/Endpoints/User.php | 4 ++-- src/Endpoints/Zones.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Endpoints/User.php b/src/Endpoints/User.php index a06c720..705d753 100644 --- a/src/Endpoints/User.php +++ b/src/Endpoints/User.php @@ -27,12 +27,12 @@ class User implements API public function getUserID(): string { - return ($this->getUserDetails())->id; + return $this->getUserDetails()->id; } public function getUserEmail(): string { - return ($this->getUserDetails())->email; + return $this->getUserDetails()->email; } public function updateUserDetails(array $details): \stdClass diff --git a/src/Endpoints/Zones.php b/src/Endpoints/Zones.php index ce9258b..c35cd3e 100644 --- a/src/Endpoints/Zones.php +++ b/src/Endpoints/Zones.php @@ -134,7 +134,7 @@ class Zones implements API */ public function changeDevelopmentMode(string $zoneID, bool $enable = false): bool { - $response = $this->adapter->patch('zones/' . $zoneID . '/settings/development_mode', [], ['value' => ($enable ? 'on' : 'off')]); + $response = $this->adapter->patch('zones/' . $zoneID . '/settings/development_mode', [], ['value' => $enable ? 'on' : 'off']); $body = json_decode($response->getBody()); From a4224265d8191de389bffd483699e211598859ea Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Tue, 21 Nov 2017 17:35:01 +0100 Subject: [PATCH 04/17] Switch from stdClass to object casting --- src/Configurations/PageRulesTargets.php | 16 +++++++++------- src/Configurations/UARules.php | 4 +--- src/Configurations/ZoneLockdown.php | 8 ++------ src/Endpoints/DNS.php | 6 +----- src/Endpoints/Railgun.php | 12 ++---------- src/Endpoints/UARules.php | 6 +----- src/Endpoints/WAF.php | 18 +++--------------- src/Endpoints/ZoneLockdown.php | 6 +----- src/Endpoints/Zones.php | 10 ++-------- tests/Endpoints/ZonesTest.php | 9 +++++---- 10 files changed, 27 insertions(+), 68 deletions(-) diff --git a/src/Configurations/PageRulesTargets.php b/src/Configurations/PageRulesTargets.php index b7e8d26..bcc614c 100644 --- a/src/Configurations/PageRulesTargets.php +++ b/src/Configurations/PageRulesTargets.php @@ -14,13 +14,15 @@ class PageRulesTargets implements Configurations public function __construct(string $queryUrl) { - $target = new \stdClass(); - $target->target = 'url'; - $target->constraint = new \stdClass(); - $target->constraint->operator = 'matches'; - $target->constraint->value = $queryUrl; - - $this->targets = [$target]; + $this->targets = [ + (object)[ + 'target' => 'url', + 'constraint' => (object)[ + 'operator' => 'matches', + 'value' => $queryUrl + ] + ] + ]; } public function getArray(): array diff --git a/src/Configurations/UARules.php b/src/Configurations/UARules.php index a4141f6..617b95a 100644 --- a/src/Configurations/UARules.php +++ b/src/Configurations/UARules.php @@ -14,9 +14,7 @@ class UARules implements Configurations public function addUA(string $value) { - $object = new \stdClass(); - $object->target = 'ua'; - $object->value = $value; + $object = (object)['target' => 'ua', 'value' => $value]; array_push($this->configs, $object); } diff --git a/src/Configurations/ZoneLockdown.php b/src/Configurations/ZoneLockdown.php index f6eee38..8ecd452 100644 --- a/src/Configurations/ZoneLockdown.php +++ b/src/Configurations/ZoneLockdown.php @@ -14,18 +14,14 @@ class ZoneLockdown implements Configurations public function addIP(string $value) { - $object = new \stdClass(); - $object->target = 'ip'; - $object->value = $value; + $object = (object)['target' => 'ip', 'value' => $value]; array_push($this->configs, $object); } public function addIPRange(string $value) { - $object = new \stdClass(); - $object->target = 'ip_range'; - $object->value = $value; + $object = (object)['target' => 'ip_range', 'value' => $value]; array_push($this->configs, $object); } diff --git a/src/Endpoints/DNS.php b/src/Endpoints/DNS.php index b3c0838..e8d134e 100644 --- a/src/Endpoints/DNS.php +++ b/src/Endpoints/DNS.php @@ -100,11 +100,7 @@ class DNS implements API $user = $this->adapter->get('zones/' . $zoneID . '/dns_records', $query, []); $body = json_decode($user->getBody()); - $result = new \stdClass(); - $result->result = $body->result; - $result->result_info = $body->result_info; - - return $result; + return (object)['result' => $body->result, 'result_info' => $body->result_info]; } public function getRecordDetails(string $zoneID, string $recordID): \stdClass diff --git a/src/Endpoints/Railgun.php b/src/Endpoints/Railgun.php index 1d4bccd..fe035bd 100644 --- a/src/Endpoints/Railgun.php +++ b/src/Endpoints/Railgun.php @@ -49,11 +49,7 @@ class Railgun implements API $user = $this->adapter->get('railguns', $query, []); $body = json_decode($user->getBody()); - $result = new \stdClass(); - $result->result = $body->result; - $result->result_info = $body->result_info; - - return $result; + return (object)['result' => $body->result, 'result_info' => $body->result_info]; } public function get( @@ -71,11 +67,7 @@ class Railgun implements API $user = $this->adapter->get('railguns/' . $railgunID . '/zones', [], []); $body = json_decode($user->getBody()); - $result = new \stdClass(); - $result->result = $body->result; - $result->result_info = $body->result_info; - - return $result; + return (object)['result' => $body->result, 'result_info' => $body->result_info]; } public function update( diff --git a/src/Endpoints/UARules.php b/src/Endpoints/UARules.php index 6eb0efb..9603caa 100644 --- a/src/Endpoints/UARules.php +++ b/src/Endpoints/UARules.php @@ -33,11 +33,7 @@ class UARules implements API $user = $this->adapter->get('zones/' . $zoneID . '/firewall/ua_rules', $query, []); $body = json_decode($user->getBody()); - $result = new \stdClass(); - $result->result = $body->result; - $result->result_info = $body->result_info; - - return $result; + return (object)['result' => $body->result, 'result_info' => $body->result_info]; } public function createRule( diff --git a/src/Endpoints/WAF.php b/src/Endpoints/WAF.php index 805c8ab..2f910c0 100644 --- a/src/Endpoints/WAF.php +++ b/src/Endpoints/WAF.php @@ -44,11 +44,7 @@ class WAF implements API $user = $this->adapter->get('zones/' . $zoneID . '/firewall/waf/packages', $query, []); $body = json_decode($user->getBody()); - $result = new \stdClass(); - $result->result = $body->result; - $result->result_info = $body->result_info; - - return $result; + return (object)['result' => $body->result, 'result_info' => $body->result_info]; } @@ -87,11 +83,7 @@ class WAF implements API $user = $this->adapter->get('zones/' . $zoneID . '/firewall/waf/packages/' . $packageID . '/rules', $query, []); $body = json_decode($user->getBody()); - $result = new \stdClass(); - $result->result = $body->result; - $result->result_info = $body->result_info; - - return $result; + return (object)['result' => $body->result, 'result_info' => $body->result_info]; } public function getRuleInfo( @@ -159,11 +151,7 @@ class WAF implements API ); $body = json_decode($user->getBody()); - $result = new \stdClass(); - $result->result = $body->result; - $result->result_info = $body->result_info; - - return $result; + return (object)['result' => $body->result, 'result_info' => $body->result_info]; } public function getGroupInfo( diff --git a/src/Endpoints/ZoneLockdown.php b/src/Endpoints/ZoneLockdown.php index a827e59..94ede81 100644 --- a/src/Endpoints/ZoneLockdown.php +++ b/src/Endpoints/ZoneLockdown.php @@ -32,11 +32,7 @@ class ZoneLockdown implements API $user = $this->adapter->get('zones/' . $zoneID . '/firewall/lockdowns', $query, []); $body = json_decode($user->getBody()); - $result = new \stdClass(); - $result->result = $body->result; - $result->result_info = $body->result_info; - - return $result; + return (object)['result' => $body->result, 'result_info' => $body->result_info]; } public function createLockdown( diff --git a/src/Endpoints/Zones.php b/src/Endpoints/Zones.php index c35cd3e..370bae6 100644 --- a/src/Endpoints/Zones.php +++ b/src/Endpoints/Zones.php @@ -35,9 +35,7 @@ class Zones implements API ]; if (!empty($organizationID)) { - $organization = new \stdClass(); - $organization->id = $organizationID; - $options['organization'] = $organization; + $options['organization'] = (object)['id' => $organizationID]; } $user = $this->adapter->post('zones', [], $options); @@ -91,11 +89,7 @@ class Zones implements API $user = $this->adapter->get('zones', $query, []); $body = json_decode($user->getBody()); - $result = new \stdClass(); - $result->result = $body->result; - $result->result_info = $body->result_info; - - return $result; + return (object)['result' => $body->result, 'result_info' => $body->result_info]; } public function getZoneID(string $name = ''): string diff --git a/tests/Endpoints/ZonesTest.php b/tests/Endpoints/ZonesTest.php index c9ff843..b4302ff 100644 --- a/tests/Endpoints/ZonesTest.php +++ b/tests/Endpoints/ZonesTest.php @@ -34,15 +34,16 @@ class ZonesTest extends TestCase $mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock(); $mock->method('post')->willReturn($response); - $org = new stdClass(); - $org->id = '01a7362d577a6c3019a474fd6f485823'; - $mock->expects($this->once()) ->method('post') ->with( $this->equalTo('zones'), $this->equalTo([]), - $this->equalTo(['name' => 'example.com', 'jumpstart' => true, 'organization' => $org]) + $this->equalTo([ + 'name' => 'example.com', + 'jumpstart' => true, + 'organization' => (object)['id' => '01a7362d577a6c3019a474fd6f485823'] + ]) ); $zones = new \Cloudflare\API\Endpoints\Zones($mock); From dac1e15e2d34c35a3ee2a8d2db2d723e10d2177b Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Tue, 21 Nov 2017 17:35:58 +0100 Subject: [PATCH 05/17] Fix loop which doesn't loop --- src/Adapter/Guzzle.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Adapter/Guzzle.php b/src/Adapter/Guzzle.php index 03dc868..78acf3d 100644 --- a/src/Adapter/Guzzle.php +++ b/src/Adapter/Guzzle.php @@ -122,9 +122,7 @@ class Guzzle implements Adapter } if (isset($json->errors)) { - foreach ($json->errors as $error) { - throw new ResponseException($error->message, $error->code); - } + throw new ResponseException($json->errors[0]->message, $json->errors[0]->code); } if (isset($json->success) && ($json->success === false)) { From 90eaea7be2b5d28b0873adb2b9ea42ce1258bc54 Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Tue, 21 Nov 2017 17:39:42 +0100 Subject: [PATCH 06/17] Use === null instead --- src/Endpoints/PageRules.php | 8 ++++---- src/Endpoints/Zones.php | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Endpoints/PageRules.php b/src/Endpoints/PageRules.php index c8be3ab..bc0bea5 100644 --- a/src/Endpoints/PageRules.php +++ b/src/Endpoints/PageRules.php @@ -70,19 +70,19 @@ class PageRules implements API string $direction = null, string $match = null ): array { - if (is_null($status) && !in_array($status, ['active', 'disabled'])) { + if ($status === null && !in_array($status, ['active', 'disabled'])) { throw new EndpointException('Page Rules can only be listed by status of active or disabled.'); } - if (is_null($order) && !in_array($order, ['status', 'priority'])) { + if ($order === null && !in_array($order, ['status', 'priority'])) { throw new EndpointException('Page Rules can only be ordered by status or priority.'); } - if (is_null($direction) && !in_array($direction, ['asc', 'desc'])) { + if ($direction === null && !in_array($direction, ['asc', 'desc'])) { throw new EndpointException('Direction of Page Rule ordering can only be asc or desc.'); } - if (is_null($match) && !in_array($match, ['all', 'any'])) { + if ($match === null && !in_array($match, ['all', 'any'])) { throw new EndpointException('Match can only be any or all.'); } diff --git a/src/Endpoints/Zones.php b/src/Endpoints/Zones.php index 370bae6..c06fd27 100644 --- a/src/Endpoints/Zones.php +++ b/src/Endpoints/Zones.php @@ -160,7 +160,7 @@ class Zones implements API public function cachePurge(string $zoneID, array $files = null, array $tags = null): bool { - if (is_null($files) && is_null($tags)) { + if ($files === null && $tags === null) { throw new EndpointException('No files or tags to purge.'); } From ee4a42ea0689ba965772f6a25cc142ff68ec8d1d Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Tue, 21 Nov 2017 17:41:21 +0100 Subject: [PATCH 07/17] Replace alias functions with origin functions --- src/Endpoints/Zones.php | 2 +- tests/Auth/APIKeyTest.php | 2 +- tests/Auth/UserServiceKeyTest.php | 2 +- tests/Configurations/ConfigurationsUARulesTest.php | 2 +- tests/Configurations/PageRulesTargetTest.php | 2 +- tests/Configurations/ZoneLockdownTest.php | 4 ++-- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Endpoints/Zones.php b/src/Endpoints/Zones.php index c06fd27..90427d7 100644 --- a/src/Endpoints/Zones.php +++ b/src/Endpoints/Zones.php @@ -96,7 +96,7 @@ class Zones implements API { $zones = $this->listZones($name); - if (sizeof($zones->result) < 1) { + if (count($zones->result) < 1) { throw new EndpointException('Could not find zones with specified name.'); } diff --git a/tests/Auth/APIKeyTest.php b/tests/Auth/APIKeyTest.php index 039f71a..6e7768b 100644 --- a/tests/Auth/APIKeyTest.php +++ b/tests/Auth/APIKeyTest.php @@ -18,6 +18,6 @@ class APIKeyTest extends TestCase $this->assertEquals('example@example.com', $headers['X-Auth-Email']); $this->assertEquals('1234567893feefc5f0q5000bfo0c38d90bbeb', $headers['X-Auth-Key']); - $this->assertEquals(2, sizeof($headers)); + $this->assertEquals(2, count($headers)); } } diff --git a/tests/Auth/UserServiceKeyTest.php b/tests/Auth/UserServiceKeyTest.php index 48b1893..f746785 100644 --- a/tests/Auth/UserServiceKeyTest.php +++ b/tests/Auth/UserServiceKeyTest.php @@ -19,6 +19,6 @@ class UserServiceKeyTest extends TestCase $headers['X-Auth-User-Service-Key'] ); - $this->assertEquals(1, sizeof($headers)); + $this->assertEquals(1, count($headers)); } } diff --git a/tests/Configurations/ConfigurationsUARulesTest.php b/tests/Configurations/ConfigurationsUARulesTest.php index c9a6301..a2fe0a1 100644 --- a/tests/Configurations/ConfigurationsUARulesTest.php +++ b/tests/Configurations/ConfigurationsUARulesTest.php @@ -14,7 +14,7 @@ class ConfigurationsUARulesTest extends TestCase $configuration->addUA('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/603.2.4 (KHTML, like Gecko) Version/10.1.1 Safari/603.2.4'); $array = $configuration->getArray(); - $this->assertEquals(1, sizeof($array)); + $this->assertEquals(1, count($array)); $this->assertObjectHasAttribute('target', $array[0]); $this->assertEquals('ua', $array[0]->target); diff --git a/tests/Configurations/PageRulesTargetTest.php b/tests/Configurations/PageRulesTargetTest.php index dbae7aa..fcf2a51 100644 --- a/tests/Configurations/PageRulesTargetTest.php +++ b/tests/Configurations/PageRulesTargetTest.php @@ -15,7 +15,7 @@ class PageRulesTargetTest extends TestCase $targets = new PageRulesTargets('junade.com/*'); $array = $targets->getArray(); - $this->assertEquals(1, sizeof($array)); + $this->assertEquals(1, count($array)); $this->assertEquals('junade.com/*', $array[0]->constraint->value); $this->assertEquals('matches', $array[0]->constraint->operator); } diff --git a/tests/Configurations/ZoneLockdownTest.php b/tests/Configurations/ZoneLockdownTest.php index 96ee1a8..dd37165 100644 --- a/tests/Configurations/ZoneLockdownTest.php +++ b/tests/Configurations/ZoneLockdownTest.php @@ -14,7 +14,7 @@ class ConfigurationZoneLockdownTest extends TestCase $configuration->addIP('1.2.3.4'); $array = $configuration->getArray(); - $this->assertEquals(1, sizeof($array)); + $this->assertEquals(1, count($array)); $this->assertObjectHasAttribute('target', $array[0]); $this->assertEquals('ip', $array[0]->target); @@ -24,7 +24,7 @@ class ConfigurationZoneLockdownTest extends TestCase $configuration->addIPRange('1.2.3.4/24'); $array = $configuration->getArray(); - $this->assertEquals(2, sizeof($array)); + $this->assertEquals(2, count($array)); $this->assertObjectHasAttribute('target', $array[1]); $this->assertEquals('ip_range', $array[1]->target); From 5caae7437032a8c270a89706253d74ce5909a7f4 Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Tue, 21 Nov 2017 17:43:47 +0100 Subject: [PATCH 08/17] Use $array[] instead of array_push --- src/Configurations/PageRulesActions.php | 2 +- src/Configurations/UARules.php | 4 +--- src/Configurations/ZoneLockdown.php | 8 ++------ 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/Configurations/PageRulesActions.php b/src/Configurations/PageRulesActions.php index 9eecc7e..6e141c2 100644 --- a/src/Configurations/PageRulesActions.php +++ b/src/Configurations/PageRulesActions.php @@ -301,7 +301,7 @@ class PageRulesActions implements Configurations { $configuration['id'] = $setting; - array_push($this->configs, (object) $configuration); + $this->configs[] = (object) $configuration; } private function getBoolAsOnOrOff(bool $value): string diff --git a/src/Configurations/UARules.php b/src/Configurations/UARules.php index 617b95a..f90d152 100644 --- a/src/Configurations/UARules.php +++ b/src/Configurations/UARules.php @@ -14,9 +14,7 @@ class UARules implements Configurations public function addUA(string $value) { - $object = (object)['target' => 'ua', 'value' => $value]; - - array_push($this->configs, $object); + $this->configs[] = (object)['target' => 'ua', 'value' => $value]; } public function getArray(): array diff --git a/src/Configurations/ZoneLockdown.php b/src/Configurations/ZoneLockdown.php index 8ecd452..d4c7ae1 100644 --- a/src/Configurations/ZoneLockdown.php +++ b/src/Configurations/ZoneLockdown.php @@ -14,16 +14,12 @@ class ZoneLockdown implements Configurations public function addIP(string $value) { - $object = (object)['target' => 'ip', 'value' => $value]; - - array_push($this->configs, $object); + $this->configs[] = (object)['target' => 'ip', 'value' => $value]; } public function addIPRange(string $value) { - $object = (object)['target' => 'ip_range', 'value' => $value]; - - array_push($this->configs, $object); + $this->configs[] = (object)['target' => 'ip_range', 'value' => $value]; } public function getArray(): array From bc9e15a5576ce5c47b1dda011a4439cfcd54049b Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Tue, 21 Nov 2017 17:46:07 +0100 Subject: [PATCH 09/17] Required parameter is missing --- src/Endpoints/UARules.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Endpoints/UARules.php b/src/Endpoints/UARules.php index 9603caa..a7ac75a 100644 --- a/src/Endpoints/UARules.php +++ b/src/Endpoints/UARules.php @@ -69,7 +69,7 @@ class UARules implements API public function getRuleDetails(string $zoneID, string $blockID): \stdClass { - $user = $this->adapter->get('zones/' . $zoneID . '/firewall/ua_rules/' . $blockID, []); + $user = $this->adapter->get('zones/' . $zoneID . '/firewall/ua_rules/' . $blockID, [], []); $body = json_decode($user->getBody()); return $body->result; } From f6cb9a8e302a382b74d08e5b0bef07e4f64bfdf7 Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Tue, 21 Nov 2017 17:46:53 +0100 Subject: [PATCH 10/17] Argument PHPDoc missing --- src/Adapter/Adapter.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Adapter/Adapter.php b/src/Adapter/Adapter.php index 9c4775e..b793f31 100644 --- a/src/Adapter/Adapter.php +++ b/src/Adapter/Adapter.php @@ -31,6 +31,7 @@ interface Adapter * RFCs, it is never useful). * * @param String $uri + * @param array $query * @param array $headers * * @return mixed From a09478eb2fda9ae3217135d04f5fab3ae8116a37 Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Tue, 21 Nov 2017 17:47:22 +0100 Subject: [PATCH 11/17] Return type doesn't match --- tests/TestCase.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/TestCase.php b/tests/TestCase.php index 50cc296..b7aedf2 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -11,7 +11,7 @@ abstract class TestCase extends PHPUnit_Framework_TestCase * Returns a PSR7 Stream for a given fixture. * * @param string $fixture The fixture to create the stream for. - * @return Psr7Stream + * @return Psr7\Stream */ protected function getPsr7StreamForFixture($fixture): Psr7\Stream { @@ -31,7 +31,7 @@ abstract class TestCase extends PHPUnit_Framework_TestCase * * @param string $fixture The fixture to create the response for. * @param integer $statusCode A HTTP Status Code for the response. - * @return Psr7Response + * @return Psr7\Response */ protected function getPsr7JsonResponseForFixture($fixture, $statusCode = 200): Psr7\Response { From 0aa9f6c05a5dbfab0dce08015b4b2962eff447c3 Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Tue, 21 Nov 2017 17:48:03 +0100 Subject: [PATCH 12/17] Fix null pointer exception --- src/Endpoints/PageRules.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Endpoints/PageRules.php b/src/Endpoints/PageRules.php index bc0bea5..0ff3f33 100644 --- a/src/Endpoints/PageRules.php +++ b/src/Endpoints/PageRules.php @@ -115,7 +115,7 @@ class PageRules implements API ): bool { $options = []; - if ($active !== null) { + if ($target !== null) { $options['targets'] = $target->getArray(); } From b15b4ecc5157019b38887b93914acc103487c94a Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Tue, 21 Nov 2017 17:49:29 +0100 Subject: [PATCH 13/17] Class autoloading correctness --- ...{ZoneLockdownTest.php => ConfigurationsZoneLockdownTest.php} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename tests/Configurations/{ZoneLockdownTest.php => ConfigurationsZoneLockdownTest.php} (94%) diff --git a/tests/Configurations/ZoneLockdownTest.php b/tests/Configurations/ConfigurationsZoneLockdownTest.php similarity index 94% rename from tests/Configurations/ZoneLockdownTest.php rename to tests/Configurations/ConfigurationsZoneLockdownTest.php index dd37165..b110cd7 100644 --- a/tests/Configurations/ZoneLockdownTest.php +++ b/tests/Configurations/ConfigurationsZoneLockdownTest.php @@ -6,7 +6,7 @@ * Date: 05/09/2017 * Time: 13:50 */ -class ConfigurationZoneLockdownTest extends TestCase +class ConfigurationsZoneLockdownTest extends TestCase { public function testGetArray() { From c9d21466aa1b513720d04e407ec3ac4426b7f363 Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Tue, 21 Nov 2017 17:50:28 +0100 Subject: [PATCH 14/17] assertCount should be used instead --- tests/Auth/APIKeyTest.php | 2 +- tests/Auth/UserServiceKeyTest.php | 2 +- tests/Configurations/ConfigurationsUARulesTest.php | 2 +- tests/Configurations/ConfigurationsZoneLockdownTest.php | 4 ++-- tests/Configurations/PageRulesTargetTest.php | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/Auth/APIKeyTest.php b/tests/Auth/APIKeyTest.php index 6e7768b..10a788b 100644 --- a/tests/Auth/APIKeyTest.php +++ b/tests/Auth/APIKeyTest.php @@ -18,6 +18,6 @@ class APIKeyTest extends TestCase $this->assertEquals('example@example.com', $headers['X-Auth-Email']); $this->assertEquals('1234567893feefc5f0q5000bfo0c38d90bbeb', $headers['X-Auth-Key']); - $this->assertEquals(2, count($headers)); + $this->assertCount(2, $headers); } } diff --git a/tests/Auth/UserServiceKeyTest.php b/tests/Auth/UserServiceKeyTest.php index f746785..53e29b3 100644 --- a/tests/Auth/UserServiceKeyTest.php +++ b/tests/Auth/UserServiceKeyTest.php @@ -19,6 +19,6 @@ class UserServiceKeyTest extends TestCase $headers['X-Auth-User-Service-Key'] ); - $this->assertEquals(1, count($headers)); + $this->assertCount(1, $headers); } } diff --git a/tests/Configurations/ConfigurationsUARulesTest.php b/tests/Configurations/ConfigurationsUARulesTest.php index a2fe0a1..aeecbf5 100644 --- a/tests/Configurations/ConfigurationsUARulesTest.php +++ b/tests/Configurations/ConfigurationsUARulesTest.php @@ -14,7 +14,7 @@ class ConfigurationsUARulesTest extends TestCase $configuration->addUA('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/603.2.4 (KHTML, like Gecko) Version/10.1.1 Safari/603.2.4'); $array = $configuration->getArray(); - $this->assertEquals(1, count($array)); + $this->assertCount(1, $array); $this->assertObjectHasAttribute('target', $array[0]); $this->assertEquals('ua', $array[0]->target); diff --git a/tests/Configurations/ConfigurationsZoneLockdownTest.php b/tests/Configurations/ConfigurationsZoneLockdownTest.php index b110cd7..e4282cc 100644 --- a/tests/Configurations/ConfigurationsZoneLockdownTest.php +++ b/tests/Configurations/ConfigurationsZoneLockdownTest.php @@ -14,7 +14,7 @@ class ConfigurationsZoneLockdownTest extends TestCase $configuration->addIP('1.2.3.4'); $array = $configuration->getArray(); - $this->assertEquals(1, count($array)); + $this->assertCount(1, $array); $this->assertObjectHasAttribute('target', $array[0]); $this->assertEquals('ip', $array[0]->target); @@ -24,7 +24,7 @@ class ConfigurationsZoneLockdownTest extends TestCase $configuration->addIPRange('1.2.3.4/24'); $array = $configuration->getArray(); - $this->assertEquals(2, count($array)); + $this->assertCount(2, $array); $this->assertObjectHasAttribute('target', $array[1]); $this->assertEquals('ip_range', $array[1]->target); diff --git a/tests/Configurations/PageRulesTargetTest.php b/tests/Configurations/PageRulesTargetTest.php index fcf2a51..a3b563a 100644 --- a/tests/Configurations/PageRulesTargetTest.php +++ b/tests/Configurations/PageRulesTargetTest.php @@ -15,7 +15,7 @@ class PageRulesTargetTest extends TestCase $targets = new PageRulesTargets('junade.com/*'); $array = $targets->getArray(); - $this->assertEquals(1, count($array)); + $this->assertCount(1, $array); $this->assertEquals('junade.com/*', $array[0]->constraint->value); $this->assertEquals('matches', $array[0]->constraint->operator); } From e1864a68246228f900ff0b6dd374b77934fbfb25 Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Tue, 21 Nov 2017 17:52:59 +0100 Subject: [PATCH 15/17] Drop unneeded arguments --- tests/Endpoints/DNSTest.php | 2 +- tests/Endpoints/UARulesTest.php | 2 +- tests/Endpoints/WAFTest.php | 6 +++--- tests/Endpoints/ZoneLockdownTest.php | 2 +- tests/Endpoints/ZonesTest.php | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/Endpoints/DNSTest.php b/tests/Endpoints/DNSTest.php index ceef67d..9ff842d 100644 --- a/tests/Endpoints/DNSTest.php +++ b/tests/Endpoints/DNSTest.php @@ -57,7 +57,7 @@ class DNSTest extends TestCase ); $zones = new \Cloudflare\API\Endpoints\DNS($mock); - $result = $zones->listRecords('023e105f4ecef8ad9ca31a8372d0c353', 'A', 'example.com', '127.0.0.1', 1, 20, 'type', 'desc', 'all'); + $result = $zones->listRecords('023e105f4ecef8ad9ca31a8372d0c353', 'A', 'example.com', '127.0.0.1', 1, 20, 'type', 'desc'); $this->assertObjectHasAttribute('result', $result); $this->assertObjectHasAttribute('result_info', $result); diff --git a/tests/Endpoints/UARulesTest.php b/tests/Endpoints/UARulesTest.php index b8ba884..15a9c70 100644 --- a/tests/Endpoints/UARulesTest.php +++ b/tests/Endpoints/UARulesTest.php @@ -27,7 +27,7 @@ class UARulesTest extends TestCase ); $zones = new \Cloudflare\API\Endpoints\UARules($mock); - $result = $zones->listRules('023e105f4ecef8ad9ca31a8372d0c353', 1, 20); + $result = $zones->listRules('023e105f4ecef8ad9ca31a8372d0c353'); $this->assertObjectHasAttribute('result', $result); $this->assertObjectHasAttribute('result_info', $result); diff --git a/tests/Endpoints/WAFTest.php b/tests/Endpoints/WAFTest.php index 40ae35f..94c7d3b 100644 --- a/tests/Endpoints/WAFTest.php +++ b/tests/Endpoints/WAFTest.php @@ -32,7 +32,7 @@ class WAFTest extends TestCase ); $waf = new \Cloudflare\API\Endpoints\WAF($mock); - $result = $waf->getPackages('023e105f4ecef8ad9ca31a8372d0c353', 1, 20, 'status', 'desc', 'all'); + $result = $waf->getPackages('023e105f4ecef8ad9ca31a8372d0c353', 1, 20, 'status', 'desc'); $this->assertObjectHasAttribute('result', $result); $this->assertObjectHasAttribute('result_info', $result); @@ -83,7 +83,7 @@ class WAFTest extends TestCase ); $waf = new \Cloudflare\API\Endpoints\WAF($mock); - $result = $waf->getRules('023e105f4ecef8ad9ca31a8372d0c353', 'a25a9a7e9c00afc1fb2e0245519d725b', 1, 20, 'status', 'desc', 'all'); + $result = $waf->getRules('023e105f4ecef8ad9ca31a8372d0c353', 'a25a9a7e9c00afc1fb2e0245519d725b', 1, 20, 'status', 'desc'); $this->assertObjectHasAttribute('result', $result); $this->assertObjectHasAttribute('result_info', $result); @@ -163,7 +163,7 @@ class WAFTest extends TestCase ); $waf = new \Cloudflare\API\Endpoints\WAF($mock); - $result = $waf->getGroups('023e105f4ecef8ad9ca31a8372d0c353', 'a25a9a7e9c00afc1fb2e0245519d725b', 1, 20, 'status', 'desc', 'all'); + $result = $waf->getGroups('023e105f4ecef8ad9ca31a8372d0c353', 'a25a9a7e9c00afc1fb2e0245519d725b', 1, 20, 'status', 'desc'); $this->assertObjectHasAttribute('result', $result); $this->assertObjectHasAttribute('result_info', $result); diff --git a/tests/Endpoints/ZoneLockdownTest.php b/tests/Endpoints/ZoneLockdownTest.php index f534de5..6892d76 100644 --- a/tests/Endpoints/ZoneLockdownTest.php +++ b/tests/Endpoints/ZoneLockdownTest.php @@ -27,7 +27,7 @@ class ZoneLockdownTest extends TestCase ); $zones = new \Cloudflare\API\Endpoints\ZoneLockdown($mock); - $result = $zones->listLockdowns('023e105f4ecef8ad9ca31a8372d0c353', 1, 20); + $result = $zones->listLockdowns('023e105f4ecef8ad9ca31a8372d0c353'); $this->assertObjectHasAttribute('result', $result); $this->assertObjectHasAttribute('result_info', $result); diff --git a/tests/Endpoints/ZonesTest.php b/tests/Endpoints/ZonesTest.php index b4302ff..990ec1d 100644 --- a/tests/Endpoints/ZonesTest.php +++ b/tests/Endpoints/ZonesTest.php @@ -95,7 +95,7 @@ class ZonesTest extends TestCase ); $zones = new \Cloudflare\API\Endpoints\Zones($mock); - $result = $zones->listZones('example.com', 'active', 1, 20, 'status', 'desc', 'all'); + $result = $zones->listZones('example.com', 'active', 1, 20, 'status', 'desc'); $this->assertObjectHasAttribute('result', $result); $this->assertObjectHasAttribute('result_info', $result); From dfa299c895011d54d82724f6ea2f749e325acdc2 Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Tue, 21 Nov 2017 17:54:30 +0100 Subject: [PATCH 16/17] Remove unused imports --- tests/Auth/NoneTest.php | 2 -- tests/Endpoints/IPsTest.php | 2 -- tests/Endpoints/PageRulesTest.php | 2 -- tests/Endpoints/RailgunTest.php | 2 -- tests/Endpoints/WAFTest.php | 2 -- 5 files changed, 10 deletions(-) diff --git a/tests/Auth/NoneTest.php b/tests/Auth/NoneTest.php index c72da6a..7e46b42 100644 --- a/tests/Auth/NoneTest.php +++ b/tests/Auth/NoneTest.php @@ -6,8 +6,6 @@ * Time: 20:08 */ -use Cloudflare\API\Auth\None; - class NoneTest extends TestCase { public function testGetHeaders() diff --git a/tests/Endpoints/IPsTest.php b/tests/Endpoints/IPsTest.php index de81da1..b32d709 100644 --- a/tests/Endpoints/IPsTest.php +++ b/tests/Endpoints/IPsTest.php @@ -6,8 +6,6 @@ * Time: 20:16 */ -use Cloudflare\API\Endpoints\IPs; - class IPsTest extends TestCase { public function testListIPs() diff --git a/tests/Endpoints/PageRulesTest.php b/tests/Endpoints/PageRulesTest.php index 7c580d0..0a84033 100644 --- a/tests/Endpoints/PageRulesTest.php +++ b/tests/Endpoints/PageRulesTest.php @@ -6,8 +6,6 @@ * Time: 19:25 */ -use Cloudflare\API\Adapter\PageRules; - class PageRulesTest extends TestCase { public function testCreatePageRule() diff --git a/tests/Endpoints/RailgunTest.php b/tests/Endpoints/RailgunTest.php index 1126a84..1374e2a 100644 --- a/tests/Endpoints/RailgunTest.php +++ b/tests/Endpoints/RailgunTest.php @@ -6,8 +6,6 @@ * Time: 11:20 */ -use Cloudflare\API\Endpoints\Railgun; - class RailgunTest extends TestCase { public function testcreate() diff --git a/tests/Endpoints/WAFTest.php b/tests/Endpoints/WAFTest.php index 94c7d3b..de5f950 100644 --- a/tests/Endpoints/WAFTest.php +++ b/tests/Endpoints/WAFTest.php @@ -6,8 +6,6 @@ * Time: 13:34 */ -use Cloudflare\API\Endpoints\WAF; - class WAFTest extends TestCase { public function testgetPackages() From ff42f334a5ec0a560941664715969a7f9846fc54 Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Tue, 21 Nov 2017 17:57:31 +0100 Subject: [PATCH 17/17] PHP !== Java --- src/Adapter/Adapter.php | 24 ++++++++++++------------ src/Adapter/Guzzle.php | 12 ++++++------ src/Auth/APIKey.php | 2 +- src/Auth/UserServiceKey.php | 2 +- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/Adapter/Adapter.php b/src/Adapter/Adapter.php index b793f31..b30a561 100644 --- a/src/Adapter/Adapter.php +++ b/src/Adapter/Adapter.php @@ -21,56 +21,56 @@ interface Adapter * Adapter constructor. * * @param Auth $auth - * @param String $baseURI + * @param string $baseURI */ - public function __construct(Auth $auth, String $baseURI); + public function __construct(Auth $auth, string $baseURI); /** * Sends a GET request. * Per Robustness Principle - not including the ability to send a body with a GET request (though possible in the * RFCs, it is never useful). * - * @param String $uri + * @param string $uri * @param array $query * @param array $headers * * @return mixed */ - public function get(String $uri, array $query, array $headers): ResponseInterface; + public function get(string $uri, array $query, array $headers): ResponseInterface; /** - * @param String $uri + * @param string $uri * @param array $headers * @param array $body * * @return mixed */ - public function post(String $uri, array $headers, array $body): ResponseInterface; + public function post(string $uri, array $headers, array $body): ResponseInterface; /** - * @param String $uri + * @param string $uri * @param array $headers * @param array $body * * @return mixed */ - public function put(String $uri, array $headers, array $body): ResponseInterface; + public function put(string $uri, array $headers, array $body): ResponseInterface; /** - * @param String $uri + * @param string $uri * @param array $headers * @param array $body * * @return mixed */ - public function patch(String $uri, array $headers, array $body): ResponseInterface; + public function patch(string $uri, array $headers, array $body): ResponseInterface; /** - * @param String $uri + * @param string $uri * @param array $headers * @param array $body * * @return mixed */ - public function delete(String $uri, array $headers, array $body): ResponseInterface; + public function delete(string $uri, array $headers, array $body): ResponseInterface; } diff --git a/src/Adapter/Guzzle.php b/src/Adapter/Guzzle.php index 78acf3d..b3bb327 100644 --- a/src/Adapter/Guzzle.php +++ b/src/Adapter/Guzzle.php @@ -18,7 +18,7 @@ class Guzzle implements Adapter /** * @inheritDoc */ - public function __construct(Auth $auth, String $baseURI = null) + public function __construct(Auth $auth, string $baseURI = null) { if ($baseURI === null) { $baseURI = 'https://api.cloudflare.com/client/v4/'; @@ -37,7 +37,7 @@ class Guzzle implements Adapter /** * @inheritDoc */ - public function get(String $uri, array $query = [], array $headers = []): ResponseInterface + public function get(string $uri, array $query = [], array $headers = []): ResponseInterface { $response = $this->client->get($uri, ['query' => $query, 'headers' => $headers]); @@ -48,7 +48,7 @@ class Guzzle implements Adapter /** * @inheritDoc */ - public function post(String $uri, array $headers = [], array $body = []): ResponseInterface + public function post(string $uri, array $headers = [], array $body = []): ResponseInterface { $response = $this->client->post( $uri, @@ -65,7 +65,7 @@ class Guzzle implements Adapter /** * @inheritDoc */ - public function put(String $uri, array $headers = [], array $body = []): ResponseInterface + public function put(string $uri, array $headers = [], array $body = []): ResponseInterface { $response = $this->client->put( $uri, @@ -82,7 +82,7 @@ class Guzzle implements Adapter /** * @inheritDoc */ - public function patch(String $uri, array $headers = [], array $body = []): ResponseInterface + public function patch(string $uri, array $headers = [], array $body = []): ResponseInterface { $response = $this->client->patch( $uri, @@ -99,7 +99,7 @@ class Guzzle implements Adapter /** * @inheritDoc */ - public function delete(String $uri, array $headers = [], array $body = []): ResponseInterface + public function delete(string $uri, array $headers = [], array $body = []): ResponseInterface { $response = $this->client->delete( $uri, diff --git a/src/Auth/APIKey.php b/src/Auth/APIKey.php index ddfb1ac..c7eda4b 100644 --- a/src/Auth/APIKey.php +++ b/src/Auth/APIKey.php @@ -12,7 +12,7 @@ class APIKey implements Auth private $email; private $apiKey; - public function __construct(String $email, String $apiKey) + public function __construct(string $email, string $apiKey) { $this->email = $email; $this->apiKey = $apiKey; diff --git a/src/Auth/UserServiceKey.php b/src/Auth/UserServiceKey.php index 7f07d8b..ec9ea51 100644 --- a/src/Auth/UserServiceKey.php +++ b/src/Auth/UserServiceKey.php @@ -11,7 +11,7 @@ class UserServiceKey implements Auth { private $userServiceKey; - public function __construct(String $userServiceKey) + public function __construct(string $userServiceKey) { $this->userServiceKey = $userServiceKey; }