From 38007ffacd21bafe9da855e2bcbb48ac09ab61d1 Mon Sep 17 00:00:00 2001 From: Tristan Date: Tue, 5 Oct 2021 11:45:31 +0200 Subject: [PATCH 1/4] Fix undefined index errors --- CHANGELOG.md | 7 +++++- src/Resources/SearchResult.php | 40 +++++++++++++++++----------------- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d71bd77..5bb5ed4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,12 @@ All notable changes to `powerdns-php` will be documented in this file. Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) principles. ## Unreleased -[Compare v3.3.1 - Unreleased](https://github.com/exonet/powerdns-php/compare/v3.3.1...develop) +[Compare v3.4.0 - Unreleased](https://github.com/exonet/powerdns-php/compare/v3.4.0...develop) + +## [v3.4.0](https://github.com/exonet/powerdns-php/releases/tag/v3.4.0) - 2021-10-06 +[Compare v3.3.1 - v3.4.0](https://github.com/exonet/powerdns-php/compare/v3.3.1...v3.4.0) +### Fixed +- Filling the `SearchResult` resource no longer results in 'Undefined index' notices. (#78) ## [v3.3.1](https://github.com/exonet/powerdns-php/releases/tag/v3.3.1) - 2021-07-06 [Compare v3.3.0 - v3.3.1](https://github.com/exonet/powerdns-php/compare/v3.3.0...v3.3.1) diff --git a/src/Resources/SearchResult.php b/src/Resources/SearchResult.php index cb72c5e..af7d6d4 100644 --- a/src/Resources/SearchResult.php +++ b/src/Resources/SearchResult.php @@ -5,12 +5,12 @@ class SearchResult { /** - * @var string The content. + * @var string|null The content. */ private $content; /** - * @var bool True when disabled. + * @var bool|null True when disabled. */ private $disabled; @@ -30,17 +30,17 @@ class SearchResult private $zoneId; /** - * @var string The zone. + * @var string|null The zone. */ private $zone; /** - * @var string The record type. + * @var string|null The record type. */ private $type; /** - * @var int The TTL value. + * @var int|null The TTL value. */ private $ttl; @@ -59,9 +59,9 @@ public function __construct(?array $result = null) /** * Get the content. * - * @return string The content. + * @return string|null The content. */ - public function getContent(): string + public function getContent(): ?string { return $this->content; } @@ -69,9 +69,9 @@ public function getContent(): string /** * Get the disabled state. * - * @return bool True when disabled. + * @return bool|null True when disabled. */ - public function isDisabled(): bool + public function isDisabled(): ?bool { return $this->disabled; } @@ -109,9 +109,9 @@ public function getZoneId(): string /** * Get the zone name. * - * @return string The zone. + * @return string|null The zone. */ - public function getZone(): string + public function getZone(): ?string { return $this->zone; } @@ -119,9 +119,9 @@ public function getZone(): string /** * Get the record type. * - * @return string The record type. + * @return string|null The record type. */ - public function getType(): string + public function getType(): ?string { return $this->type; } @@ -129,9 +129,9 @@ public function getType(): string /** * Get the record Time To Live (TTL). * - * @return int The TTL. + * @return int|null The TTL. */ - public function getTtl(): int + public function getTtl(): ?int { return $this->ttl; } @@ -145,13 +145,13 @@ public function getTtl(): int */ public function setFromApiResponse(array $data): self { - $this->content = $data['content']; - $this->disabled = (bool) $data['disabled']; + $this->content = $data['content'] ?? null; + $this->disabled = isset($data['disabled']) ? (bool) $data['disabled'] : null; $this->name = $data['name']; $this->objectType = $data['object_type']; - $this->ttl = (int) $data['ttl']; - $this->type = $data['type']; - $this->zone = $data['zone']; + $this->ttl = isset($data['ttl']) ? (int) $data['ttl'] : null; + $this->type = $data['type'] ?? null; + $this->zone = $data['zone'] ?? null; $this->zoneId = $data['zone_id']; return $this; From 1790dd060dc7e84e6fa7fb7a3abca65f4caddd96 Mon Sep 17 00:00:00 2001 From: Tristan Date: Tue, 5 Oct 2021 11:46:08 +0200 Subject: [PATCH 2/4] Make methods protected instead of private --- CHANGELOG.md | 3 +++ src/Connector.php | 8 ++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5bb5ed4..3f6128a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,9 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip ## [v3.4.0](https://github.com/exonet/powerdns-php/releases/tag/v3.4.0) - 2021-10-06 [Compare v3.3.1 - v3.4.0](https://github.com/exonet/powerdns-php/compare/v3.3.1...v3.4.0) +### Changed +- The private methods in the `Connector` class are now protected instead of private. + ### Fixed - Filling the `SearchResult` resource no longer results in 'Undefined index' notices. (#78) diff --git a/src/Connector.php b/src/Connector.php index 1a5b384..143b04f 100644 --- a/src/Connector.php +++ b/src/Connector.php @@ -114,7 +114,7 @@ public function delete(string $urlPath): array * * @return mixed[] The decoded JSON response. */ - private function makeCall(string $method, string $urlPath, ?string $payload = null): array + protected function makeCall(string $method, string $urlPath, ?string $payload = null): array { $url = $this->buildUrl($urlPath); $headers = $this->getDefaultHeaders(); @@ -139,7 +139,7 @@ private function makeCall(string $method, string $urlPath, ?string $payload = nu * * @return mixed[] The decoded JSON response. */ - private function parseResponse(PsrResponse $response): array + protected function parseResponse(PsrResponse $response): array { $this->powerdns->log()->debug('Request completed', ['statusCode' => $response->getStatusCode()]); $contents = json_decode($response->getBody()->getContents(), true); @@ -170,7 +170,7 @@ private function parseResponse(PsrResponse $response): array * * @return string The complete URL. */ - private function buildUrl(string $path): string + protected function buildUrl(string $path): string { $config = $this->powerdns->getConfig(); @@ -191,7 +191,7 @@ private function buildUrl(string $path): string * * @return string[] The headers. */ - private function getDefaultHeaders(): array + protected function getDefaultHeaders(): array { return [ 'X-API-Key' => $this->powerdns->getConfig()['apiKey'], From 61ab4a80de39642596ce03ae670cbf7d2d1f60c4 Mon Sep 17 00:00:00 2001 From: Tristan Date: Tue, 5 Oct 2021 11:46:31 +0200 Subject: [PATCH 3/4] Add the overwriteConnector method --- CHANGELOG.md | 3 +++ src/Powerdns.php | 14 ++++++++++++++ tests/PowerdnsTest.php | 3 ++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f6128a..5440228 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,9 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip ## [v3.4.0](https://github.com/exonet/powerdns-php/releases/tag/v3.4.0) - 2021-10-06 [Compare v3.3.1 - v3.4.0](https://github.com/exonet/powerdns-php/compare/v3.3.1...v3.4.0) +### Added +- The `overwriteConnector` method in the Powerdns class. + ### Changed - The private methods in the `Connector` class are now protected instead of private. diff --git a/src/Powerdns.php b/src/Powerdns.php index f1f1592..addd12e 100644 --- a/src/Powerdns.php +++ b/src/Powerdns.php @@ -91,6 +91,20 @@ public function __construct( $this->connector = $connector ?? new Connector($this); } + /** + * Overwrite the configured connector instance with the provided one. + * + * @param ConnectorInterface $connector The new connector instance to use. + * + * @return $this The current Powerdns class. + */ + public function overwriteConnector(ConnectorInterface $connector): self + { + $this->connector = $connector; + + return $this; + } + /** * Configure a new connection to a PowerDNS server. * diff --git a/tests/PowerdnsTest.php b/tests/PowerdnsTest.php index f895534..831e14f 100644 --- a/tests/PowerdnsTest.php +++ b/tests/PowerdnsTest.php @@ -162,7 +162,8 @@ public function testSearch(): void ] ); - $powerDns = new Powerdns(null, null, null, null, $connector); + $powerDns = new Powerdns(); + $powerDns->overwriteConnector($connector); $searchResults = $powerDns->search('search strïng&more', 1337, 'zone'); From 239dc38338765b10f203b2bbf69a33bf4598b793 Mon Sep 17 00:00:00 2001 From: Tristan Date: Mon, 18 Oct 2021 15:32:04 +0200 Subject: [PATCH 4/4] Rename overwriteConnector to setConnector --- CHANGELOG.md | 4 ++-- src/Powerdns.php | 6 +++--- tests/PowerdnsTest.php | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5440228..746de23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,10 +7,10 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip ## Unreleased [Compare v3.4.0 - Unreleased](https://github.com/exonet/powerdns-php/compare/v3.4.0...develop) -## [v3.4.0](https://github.com/exonet/powerdns-php/releases/tag/v3.4.0) - 2021-10-06 +## [v3.4.0](https://github.com/exonet/powerdns-php/releases/tag/v3.4.0) - 2021-10-19 [Compare v3.3.1 - v3.4.0](https://github.com/exonet/powerdns-php/compare/v3.3.1...v3.4.0) ### Added -- The `overwriteConnector` method in the Powerdns class. +- The `setConnector` method in the Powerdns class. ### Changed - The private methods in the `Connector` class are now protected instead of private. diff --git a/src/Powerdns.php b/src/Powerdns.php index addd12e..c5d0ca3 100644 --- a/src/Powerdns.php +++ b/src/Powerdns.php @@ -92,13 +92,13 @@ public function __construct( } /** - * Overwrite the configured connector instance with the provided one. + * Set the configured connector instance instead of the default one. * - * @param ConnectorInterface $connector The new connector instance to use. + * @param ConnectorInterface $connector The connector instance to use. * * @return $this The current Powerdns class. */ - public function overwriteConnector(ConnectorInterface $connector): self + public function setConnector(ConnectorInterface $connector): self { $this->connector = $connector; diff --git a/tests/PowerdnsTest.php b/tests/PowerdnsTest.php index 831e14f..dd61787 100644 --- a/tests/PowerdnsTest.php +++ b/tests/PowerdnsTest.php @@ -163,7 +163,7 @@ public function testSearch(): void ); $powerDns = new Powerdns(); - $powerDns->overwriteConnector($connector); + $powerDns->setConnector($connector); $searchResults = $powerDns->search('search strïng&more', 1337, 'zone');