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);