diff --git a/.gitignore b/.gitignore index b3c4903..36e61a1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /.idea/ /vendor/ composer.lock +.phpunit.result.cache diff --git a/.styleci.yml b/.styleci.yml index f186f21..272e011 100644 --- a/.styleci.yml +++ b/.styleci.yml @@ -6,4 +6,3 @@ enabled: disabled: - align_double_arrow - - simplified_null_return diff --git a/.travis.yml b/.travis.yml index 5b9a9e1..0d51acf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,14 +1,30 @@ +dist: xenial language: php +services: + - mysql + +env: + - PDNS_VERSION=41 + - PDNS_VERSION=42 + php: - 7.1 - 7.2 - 7.3 + - 7.4 cache: directories: - vendor - $HOME/.composer/cache +before_install: + - mysql -e 'CREATE DATABASE powerdns;' + - if [[ "$PDNS_VERSION" == "41" ]]; then mysql -u root powerdns < .travis/pdns-41.sql; fi + - if [[ "$PDNS_VERSION" == "42" ]]; then mysql -u root powerdns < .travis/pdns-42.sql; fi + install: + - sudo ./.travis/install-pdns.sh - composer install + diff --git a/.travis/install-pdns.sh b/.travis/install-pdns.sh new file mode 100755 index 0000000..2f100c7 --- /dev/null +++ b/.travis/install-pdns.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +# Use the PowerDNS repo as source. +if [ "$PDNS_VERSION" = "41" ]; then + sudo echo 'deb [arch=amd64] http://repo.powerdns.com/ubuntu xenial-auth-41 main' > /etc/apt/sources.list.d/pdns.list +fi + +if [ "$PDNS_VERSION" = "42" ]; then + sudo echo 'deb [arch=amd64] http://repo.powerdns.com/ubuntu xenial-auth-42 main' > /etc/apt/sources.list.d/pdns.list +fi + +# Get the specific release and install. +curl https://repo.powerdns.com/FD380FBB-pub.asc | sudo apt-key add - && sudo apt-get update && sudo apt-get install pdns-server pdns-backend-mysql +sudo cp "$TRAVIS_BUILD_DIR/.travis/pdns.conf" /etc/powerdns/pdns.conf +sudo service pdns restart diff --git a/.travis/pdns-41.sql b/.travis/pdns-41.sql new file mode 100644 index 0000000..bf15329 --- /dev/null +++ b/.travis/pdns-41.sql @@ -0,0 +1,89 @@ +CREATE TABLE domains ( + id INT AUTO_INCREMENT, + name VARCHAR(255) NOT NULL, + master VARCHAR(128) DEFAULT NULL, + last_check INT DEFAULT NULL, + type VARCHAR(6) NOT NULL, + notified_serial INT DEFAULT NULL, + account VARCHAR(40) CHARACTER SET 'utf8' DEFAULT NULL, + PRIMARY KEY (id) +) Engine=InnoDB CHARACTER SET 'latin1'; + +CREATE UNIQUE INDEX name_index ON domains(name); + + +CREATE TABLE records ( + id BIGINT AUTO_INCREMENT, + domain_id INT DEFAULT NULL, + name VARCHAR(255) DEFAULT NULL, + type VARCHAR(10) DEFAULT NULL, + content VARCHAR(64000) DEFAULT NULL, + ttl INT DEFAULT NULL, + prio INT DEFAULT NULL, + change_date INT DEFAULT NULL, + disabled TINYINT(1) DEFAULT 0, + ordername VARCHAR(255) BINARY DEFAULT NULL, + auth TINYINT(1) DEFAULT 1, + PRIMARY KEY (id) +) Engine=InnoDB CHARACTER SET 'latin1'; + +CREATE INDEX nametype_index ON records(name,type); +CREATE INDEX domain_id ON records(domain_id); +CREATE INDEX ordername ON records (ordername); + + +CREATE TABLE supermasters ( + ip VARCHAR(64) NOT NULL, + nameserver VARCHAR(255) NOT NULL, + account VARCHAR(40) CHARACTER SET 'utf8' NOT NULL, + PRIMARY KEY (ip, nameserver) +) Engine=InnoDB CHARACTER SET 'latin1'; + + +CREATE TABLE comments ( + id INT AUTO_INCREMENT, + domain_id INT NOT NULL, + name VARCHAR(255) NOT NULL, + type VARCHAR(10) NOT NULL, + modified_at INT NOT NULL, + account VARCHAR(40) CHARACTER SET 'utf8' DEFAULT NULL, + comment TEXT CHARACTER SET 'utf8' NOT NULL, + PRIMARY KEY (id) +) Engine=InnoDB CHARACTER SET 'latin1'; + +CREATE INDEX comments_name_type_idx ON comments (name, type); +CREATE INDEX comments_order_idx ON comments (domain_id, modified_at); + + +CREATE TABLE domainmetadata ( + id INT AUTO_INCREMENT, + domain_id INT NOT NULL, + kind VARCHAR(32), + content TEXT, + PRIMARY KEY (id) +) Engine=InnoDB CHARACTER SET 'latin1'; + +CREATE INDEX domainmetadata_idx ON domainmetadata (domain_id, kind); + + +CREATE TABLE cryptokeys ( + id INT AUTO_INCREMENT, + domain_id INT NOT NULL, + flags INT NOT NULL, + active BOOL, + content TEXT, + PRIMARY KEY(id) +) Engine=InnoDB CHARACTER SET 'latin1'; + +CREATE INDEX domainidindex ON cryptokeys(domain_id); + + +CREATE TABLE tsigkeys ( + id INT AUTO_INCREMENT, + name VARCHAR(255), + algorithm VARCHAR(50), + secret VARCHAR(255), + PRIMARY KEY (id) +) Engine=InnoDB CHARACTER SET 'latin1'; + +CREATE UNIQUE INDEX namealgoindex ON tsigkeys(name, algorithm); diff --git a/.travis/pdns-42.sql b/.travis/pdns-42.sql new file mode 100644 index 0000000..1ac5e08 --- /dev/null +++ b/.travis/pdns-42.sql @@ -0,0 +1,89 @@ +CREATE TABLE domains ( + id INT AUTO_INCREMENT, + name VARCHAR(255) NOT NULL, + master VARCHAR(128) DEFAULT NULL, + last_check INT DEFAULT NULL, + type VARCHAR(6) NOT NULL, + notified_serial INT UNSIGNED DEFAULT NULL, + account VARCHAR(40) CHARACTER SET 'utf8' DEFAULT NULL, + PRIMARY KEY (id) +) Engine=InnoDB CHARACTER SET 'latin1'; + +CREATE UNIQUE INDEX name_index ON domains(name); + + +CREATE TABLE records ( + id BIGINT AUTO_INCREMENT, + domain_id INT DEFAULT NULL, + name VARCHAR(255) DEFAULT NULL, + type VARCHAR(10) DEFAULT NULL, + content VARCHAR(64000) DEFAULT NULL, + ttl INT DEFAULT NULL, + prio INT DEFAULT NULL, + disabled TINYINT(1) DEFAULT 0, + ordername VARCHAR(255) BINARY DEFAULT NULL, + auth TINYINT(1) DEFAULT 1, + PRIMARY KEY (id) +) Engine=InnoDB CHARACTER SET 'latin1'; + +CREATE INDEX nametype_index ON records(name,type); +CREATE INDEX domain_id ON records(domain_id); +CREATE INDEX ordername ON records (ordername); + + +CREATE TABLE supermasters ( + ip VARCHAR(64) NOT NULL, + nameserver VARCHAR(255) NOT NULL, + account VARCHAR(40) CHARACTER SET 'utf8' NOT NULL, + PRIMARY KEY (ip, nameserver) +) Engine=InnoDB CHARACTER SET 'latin1'; + + +CREATE TABLE comments ( + id INT AUTO_INCREMENT, + domain_id INT NOT NULL, + name VARCHAR(255) NOT NULL, + type VARCHAR(10) NOT NULL, + modified_at INT NOT NULL, + account VARCHAR(40) CHARACTER SET 'utf8' DEFAULT NULL, + comment TEXT CHARACTER SET 'utf8' NOT NULL, + PRIMARY KEY (id) +) Engine=InnoDB CHARACTER SET 'latin1'; + +CREATE INDEX comments_name_type_idx ON comments (name, type); +CREATE INDEX comments_order_idx ON comments (domain_id, modified_at); + + +CREATE TABLE domainmetadata ( + id INT AUTO_INCREMENT, + domain_id INT NOT NULL, + kind VARCHAR(32), + content TEXT, + PRIMARY KEY (id) +) Engine=InnoDB CHARACTER SET 'latin1'; + +CREATE INDEX domainmetadata_idx ON domainmetadata (domain_id, kind); + + +CREATE TABLE cryptokeys ( + id INT AUTO_INCREMENT, + domain_id INT NOT NULL, + flags INT NOT NULL, + active BOOL, + content TEXT, + PRIMARY KEY(id) +) Engine=InnoDB CHARACTER SET 'latin1'; + +CREATE INDEX domainidindex ON cryptokeys(domain_id); + + +CREATE TABLE tsigkeys ( + id INT AUTO_INCREMENT, + name VARCHAR(255), + algorithm VARCHAR(50), + secret VARCHAR(255), + PRIMARY KEY (id) +) Engine=InnoDB CHARACTER SET 'latin1'; + +CREATE UNIQUE INDEX namealgoindex ON tsigkeys(name, algorithm); + diff --git a/.travis/pdns.conf b/.travis/pdns.conf new file mode 100644 index 0000000..bd57953 --- /dev/null +++ b/.travis/pdns.conf @@ -0,0 +1,23 @@ +launch=gmysql +gmysql-host=localhost +gmysql-user=root +gmysql-password= +gmysql-dbname=powerdns +gmysql-port=3306 +gmysql-dnssec=yes + +api=yes +api-key=apiKey + +webserver=yes +webserver-port=8001 +webserver-address=0.0.0.0 +webserver-allow-from=0.0.0.0/0,::/0 + +default-soa-name=ns1.powerdns-php +default-soa-mail=hostmaster@powerdns-php + +default-ksk-algorithm=rsasha256 +default-ksk-size=2048 +default-zsk-algorithm=rsasha256 +default-zsk-size=1024 diff --git a/CHANGELOG.md b/CHANGELOG.md index 492215e..0068a95 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,25 @@ 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 v1.1.0 - Unreleased](https://github.com/exonet/powerdns-php/compare/v1.1.0...develop) +[Compare v2.0.0 - Unreleased](https://github.com/exonet/powerdns-php/compare/v2.0.0...develop) + +## [v2.0.0](https://github.com/exonet/powerdns-php/releases/tag/v2.0.0) - 2020-01-29 +[Compare v1.1.0 - v2.0.0](https://github.com/exonet/powerdns-php/compare/v1.1.0...v2.0.0) +### Breaking +- Renamed `SOA-EDIT-API` to `SOA-EDIT` when creating a new zone. +- Implemented new `SOA-EDIT-API` logic when creating a new zone that defaults to `DEFAULT` so the `SOA-EDIT` value will be used. + +This change will break your SOA increment if not configured correctly in the zone meta data. You need to update the zone +meta yourself in whatever backend you use for PowerDNS. See the following quote from the [PowerDNS website (section API)](https://doc.powerdns.com/md/authoritative/upgrading/): + +> Incompatible change: SOA-EDIT-API now follows SOA-EDIT-DNSUPDATE instead of SOA-EDIT (incl. the fact that it now has +> a default value of DEFAULT). You must update your existing SOA-EDIT-API metadata (set SOA-EDIT to your previous +> SOA-EDIT-API value, and SOA-EDIT-API to SOA-EDIT to keep the old behaviour). + +### Added +- PowerDNS 4.2 support (see 'breaking' above). +- PHP 7.4 support +- Functional tests for SOA increments. ## [v1.1.0](https://github.com/exonet/powerdns-php/releases/tag/v1.1.0) - 2019-10-21 [Compare v1.0.1 - v1.1.0](https://github.com/exonet/powerdns-php/compare/v1.0.1...v1.1.0) diff --git a/LICENSE.md b/LICENSE.md index c0a170d..9ecc46b 100755 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,6 +1,6 @@ # The MIT License (MIT) -Copyright (c) 2019 Exonet +Copyright (c) 2020 Exonet > Permission is hereby granted, free of charge, to any person obtaining a copy > of this software and associated documentation files (the "Software"), to deal diff --git a/composer.json b/composer.json index 5119cab..5e6e8a1 100755 --- a/composer.json +++ b/composer.json @@ -25,8 +25,9 @@ "psr/log": "^1.0" }, "require-dev": { + "limedeck/phpunit-detailed-printer": "^4", "mockery/mockery": "^1.2", - "phpunit/phpunit": ">=7.0" + "phpunit/phpunit": "^7" }, "autoload": { "psr-4": { diff --git a/examples/CliLogger.php b/examples/CliLogger.php index 8cc18d4..4d31be7 100644 --- a/examples/CliLogger.php +++ b/examples/CliLogger.php @@ -100,7 +100,7 @@ public static function __callStatic($foreground_color, $args) /** * {@inheritdoc} */ - public function log($level, $message, array $context = []) : void + public function log($level, $message, array $context = []): void { $foreground = self::$color[$level]['foreground']; $background = self::$color[$level]['background'] ?? null; diff --git a/phpunit.xml b/phpunit.xml index 4f42fdb..cd38055 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -6,6 +6,7 @@ bootstrap="vendor/autoload.php" cacheTokens="false" colors="true" + printerClass="LimeDeck\Testing\Printer" > diff --git a/src/AbstractZone.php b/src/AbstractZone.php index 8f3047f..c36e628 100644 --- a/src/AbstractZone.php +++ b/src/AbstractZone.php @@ -43,7 +43,7 @@ public function __construct(Connector $connector, ?string $canonicalDomain = nul * * @return $this The current class instance. */ - public function setZone(string $canonicalDomain) : self + public function setZone(string $canonicalDomain): self { $fixDot = substr($canonicalDomain, -1) !== '.'; @@ -61,7 +61,7 @@ public function setZone(string $canonicalDomain) : self * * @return ZoneResource The zone resource. */ - public function resource() : ZoneResource + public function resource(): ZoneResource { if ($this->zoneResource === null) { $zoneData = $this->connector->get($this->getZonePath()); @@ -81,7 +81,7 @@ public function resource() : ZoneResource * * @return string The API zone path. */ - protected function getZonePath(?string $path = null) : string + protected function getZonePath(?string $path = null): string { return sprintf('zones/%s%s', $this->zone, $path); } diff --git a/src/Connector.php b/src/Connector.php index ceb9877..d7f9395 100644 --- a/src/Connector.php +++ b/src/Connector.php @@ -45,7 +45,7 @@ public function __construct(Powerdns $client, ?HandlerStack $guzzleHandlerStack * * @return mixed[] The response body. */ - public function get(string $urlPath) : array + public function get(string $urlPath): array { return $this->makeCall('GET', $urlPath); } @@ -58,7 +58,7 @@ public function get(string $urlPath) : array * * @return mixed[] The response body. */ - public function post(string $urlPath, Transformer $payload) : array + public function post(string $urlPath, Transformer $payload): array { return $this->makeCall('POST', $urlPath, json_encode($payload->transform())); } @@ -71,7 +71,7 @@ public function post(string $urlPath, Transformer $payload) : array * * @return mixed[] The response body. */ - public function patch(string $urlPath, Transformer $payload) : array + public function patch(string $urlPath, Transformer $payload): array { return $this->makeCall('PATCH', $urlPath, json_encode($payload->transform())); } @@ -84,7 +84,7 @@ public function patch(string $urlPath, Transformer $payload) : array * * @return mixed[] The response body. */ - public function put(string $urlPath, Transformer $payload) : array + public function put(string $urlPath, Transformer $payload): array { return $this->makeCall('PUT', $urlPath, json_encode($payload->transform())); } @@ -96,7 +96,7 @@ public function put(string $urlPath, Transformer $payload) : array * * @return mixed[] The response body. */ - public function delete(string $urlPath) : array + public function delete(string $urlPath): array { return $this->makeCall('DELETE', $urlPath); } @@ -113,7 +113,7 @@ public function delete(string $urlPath) : array * * @return mixed[] The decoded JSON response. */ - private function makeCall(string $method, string $urlPath, ?string $payload = null) : array + private function makeCall(string $method, string $urlPath, ?string $payload = null): array { $url = $this->buildUrl($urlPath); $headers = $this->getDefaultHeaders(); @@ -138,7 +138,7 @@ private function makeCall(string $method, string $urlPath, ?string $payload = nu * * @return mixed[] The decoded JSON response. */ - private function parseResponse(PsrResponse $response) : array + private function parseResponse(PsrResponse $response): array { $this->powerdns->log()->debug('Request completed', ['statusCode' => $response->getStatusCode()]); $contents = json_decode($response->getBody()->getContents(), true); @@ -168,7 +168,7 @@ private function parseResponse(PsrResponse $response) : array * * @return string The complete URL. */ - private function buildUrl(string $path) : string + private function buildUrl(string $path): string { $config = $this->powerdns->getConfig(); @@ -186,7 +186,7 @@ private function buildUrl(string $path) : string * * @return string[] The headers. */ - private function getDefaultHeaders() : array + private function getDefaultHeaders(): array { return [ 'X-API-Key' => $this->powerdns->getConfig()['apiKey'], diff --git a/src/Cryptokey.php b/src/Cryptokey.php index c3580bb..d6dcc52 100644 --- a/src/Cryptokey.php +++ b/src/Cryptokey.php @@ -42,7 +42,7 @@ public function __construct( * * @return $this The current class instance. */ - public function setPrivateKey(string $keyContent) : self + public function setPrivateKey(string $keyContent): self { $this->createTransformer = new CryptokeyCreateTransformer(['content' => $keyContent]); @@ -58,7 +58,7 @@ public function setPrivateKey(string $keyContent) : self * * @return $this The current class instance. */ - public function configurePrivateKey(string $algorithm, ?int $bits = null, string $keyType = 'csk') : self + public function configurePrivateKey(string $algorithm, ?int $bits = null, string $keyType = 'csk'): self { $this->createTransformer = new CryptokeyCreateTransformer([ 'algorithm' => $algorithm, @@ -77,7 +77,7 @@ public function configurePrivateKey(string $algorithm, ?int $bits = null, string * * @return CryptokeyResource The created Crypto Key. */ - public function create(bool $active = false, string $keyType = 'csk') : CryptokeyResource + public function create(bool $active = false, string $keyType = 'csk'): CryptokeyResource { // Check if a transformer is already initialized. If it isn,t create one. if ($this->createTransformer === null) { @@ -102,7 +102,7 @@ public function create(bool $active = false, string $keyType = 'csk') : Cryptoke * * @return CryptokeyResource[] The active keys. */ - public function getActiveKeys() : array + public function getActiveKeys(): array { return $this->keysByActive(true); } @@ -112,7 +112,7 @@ public function getActiveKeys() : array * * @return CryptokeyResource[] The inactive keys. */ - public function getInactiveKeys() : array + public function getInactiveKeys(): array { return $this->keysByActive(false); } @@ -122,7 +122,7 @@ public function getInactiveKeys() : array * * @return int[] The IDs of the keys that are deleted. */ - public function deleteInactive() : array + public function deleteInactive(): array { $keys = $this->keysByActive(false, true); @@ -136,7 +136,7 @@ public function deleteInactive() : array * * @return int[] The IDs of the keys that are deleted. */ - public function deleteKeys(int ...$keyIds) : array + public function deleteKeys(int ...$keyIds): array { $deletedKeys = []; @@ -156,7 +156,7 @@ public function deleteKeys(int ...$keyIds) : array * * @return CryptokeyResource[] Array with Crypto Key resources. */ - public function getKeys(bool $includePrivateKey = false) : array + public function getKeys(bool $includePrivateKey = false): array { $data = $this->connector->get($this->getZonePath('/cryptokeys')); @@ -184,7 +184,7 @@ public function getKeys(bool $includePrivateKey = false) : array * * @return int[] IDs of the keys that are (de)activated. */ - public function setActive(bool $active, int ...$keyIds) : array + public function setActive(bool $active, int ...$keyIds): array { $keyIds = !empty($keyIds) ? $keyIds : $this->keysByActive(!$active, true); $activatedKeys = []; @@ -209,7 +209,7 @@ public function setActive(bool $active, int ...$keyIds) : array * * @return CryptokeyResource[]|int[] An array with Crypto Key resources or IDs. */ - private function keysByActive(bool $active, bool $asIdList = false) : array + private function keysByActive(bool $active, bool $asIdList = false): array { $keys = $this->getKeys(); $foundKeys = []; diff --git a/src/Powerdns.php b/src/Powerdns.php index ce143da..0896545 100644 --- a/src/Powerdns.php +++ b/src/Powerdns.php @@ -97,7 +97,7 @@ public function __construct( * * @return Powerdns The created PowerDNS client. */ - public function connect(string $host, int $port = 8001, string $server = 'localhost') : self + public function connect(string $host, int $port = 8001, string $server = 'localhost'): self { $this->host = $host; $this->port = $port; @@ -113,7 +113,7 @@ public function connect(string $host, int $port = 8001, string $server = 'localh * * @return $this The current client. */ - public function useKey(string $key) : self + public function useKey(string $key): self { $this->apiKey = $key; @@ -129,7 +129,7 @@ public function useKey(string $key) : self * * @return Zone The created Zone. */ - public function createZone(string $canonicalDomain, array $nameservers, bool $useDnssec = false) : Zone + public function createZone(string $canonicalDomain, array $nameservers, bool $useDnssec = false): Zone { $fixDot = substr($canonicalDomain, -1) !== '.'; @@ -155,7 +155,7 @@ public function createZone(string $canonicalDomain, array $nameservers, bool $us * * @return Zone The zone. */ - public function zone(string $canonicalDomain) : Zone + public function zone(string $canonicalDomain): Zone { return new Zone($this->connector, $canonicalDomain); } @@ -167,7 +167,7 @@ public function zone(string $canonicalDomain) : Zone * * @return bool True that the zone was removed. */ - public function deleteZone(string $canonicalDomain) : bool + public function deleteZone(string $canonicalDomain): bool { $this->connector->delete('zones/'.$canonicalDomain); @@ -179,7 +179,7 @@ public function deleteZone(string $canonicalDomain) : bool * * @return Zone[] Array containing the zones */ - public function listZones() : array + public function listZones(): array { return array_map( function (array $args) { @@ -196,7 +196,7 @@ function (array $args) { * * @return Cryptokey The cryptokey instance. */ - public function cryptokeys(string $canonicalDomain) : Cryptokey + public function cryptokeys(string $canonicalDomain): Cryptokey { return new Cryptokey($this->connector, $canonicalDomain); } @@ -206,7 +206,7 @@ public function cryptokeys(string $canonicalDomain) : Cryptokey * * @return LoggerInterface The log instance. */ - public function log() : LoggerInterface + public function log(): LoggerInterface { if ($this->logger === null) { // If there's no logger set, use the NullLogger. @@ -223,7 +223,7 @@ public function log() : LoggerInterface * * @return self The current client instance. */ - public function setLogger(LoggerInterface $log) : self + public function setLogger(LoggerInterface $log): self { $this->logger = $log; @@ -235,7 +235,7 @@ public function setLogger(LoggerInterface $log) : self * * @return mixed[] Array containing the client config items. */ - public function getConfig() : array + public function getConfig(): array { return [ 'host' => $this->host, diff --git a/src/Resources/Comment.php b/src/Resources/Comment.php index ab656cb..16eaf2a 100644 --- a/src/Resources/Comment.php +++ b/src/Resources/Comment.php @@ -26,7 +26,7 @@ class Comment * * @return string The actual comment. */ - public function getContent() : string + public function getContent(): string { return $this->content; } @@ -38,7 +38,7 @@ public function getContent() : string * * @return $this The current Comment instance. */ - public function setContent(string $content) : self + public function setContent(string $content): self { $this->content = $content; @@ -50,7 +50,7 @@ public function setContent(string $content) : self * * @return string Name of an account that added the comment. */ - public function getAccount() : string + public function getAccount(): string { return $this->account; } @@ -62,7 +62,7 @@ public function getAccount() : string * * @return $this The current Comment instance. */ - public function setAccount(string $account) : self + public function setAccount(string $account): self { $this->account = $account; @@ -74,7 +74,7 @@ public function setAccount(string $account) : self * * @return int Timestamp of the last change to the comment. */ - public function getModifiedAt() : int + public function getModifiedAt(): int { return $this->modifiedAt; } @@ -86,7 +86,7 @@ public function getModifiedAt() : int * * @return $this The current Comment instance. */ - public function setModifiedAt(int $modifiedAt) : self + public function setModifiedAt(int $modifiedAt): self { $this->modifiedAt = $modifiedAt; diff --git a/src/Resources/Cryptokey.php b/src/Resources/Cryptokey.php index dc66268..4396acc 100644 --- a/src/Resources/Cryptokey.php +++ b/src/Resources/Cryptokey.php @@ -63,7 +63,7 @@ class Cryptokey * * @return Cryptokey A fresh instance filled with data from the API. */ - public function setApiResponse(array $cryptokey) : self + public function setApiResponse(array $cryptokey): self { // Create a fresh instance of this resource. $newClass = new static(); @@ -114,7 +114,7 @@ public function setApiResponse(array $cryptokey) : self * * @return string The type. */ - public function getType() : string + public function getType(): string { return $this->type; } @@ -126,7 +126,7 @@ public function getType() : string * * @return $this The current Cryptokey instance. */ - public function setType(string $type) : self + public function setType(string $type): self { $this->type = $type; @@ -138,7 +138,7 @@ public function setType(string $type) : self * * @return int The internal identifier, read only. */ - public function getId() : int + public function getId(): int { return $this->id; } @@ -150,7 +150,7 @@ public function getId() : int * * @return $this The current Cryptokey instance. */ - public function setId(int $id) : self + public function setId(int $id): self { $this->id = $id; @@ -162,7 +162,7 @@ public function setId(int $id) : self * * @return string The key type. */ - public function getKeyType() : string + public function getKeyType(): string { return $this->keyType; } @@ -174,7 +174,7 @@ public function getKeyType() : string * * @return $this The current Cryptokey instance. */ - public function setKeyType(string $keyType) : self + public function setKeyType(string $keyType): self { $this->keyType = $keyType; @@ -186,7 +186,7 @@ public function setKeyType(string $keyType) : self * * @return bool True when active. */ - public function isActive() : bool + public function isActive(): bool { return $this->active; } @@ -198,7 +198,7 @@ public function isActive() : bool * * @return $this The current Cryptokey instance. */ - public function setActive(bool $active) : self + public function setActive(bool $active): self { $this->active = $active; @@ -210,7 +210,7 @@ public function setActive(bool $active) : self * * @return string The DNSKEY record for this key. */ - public function getDnsKey() : string + public function getDnsKey(): string { return $this->dnsKey; } @@ -222,7 +222,7 @@ public function getDnsKey() : string * * @return $this The current Cryptokey instance. */ - public function setDnsKey(string $dnsKey) : self + public function setDnsKey(string $dnsKey): self { $this->dnsKey = $dnsKey; @@ -234,7 +234,7 @@ public function setDnsKey(string $dnsKey) : self * * @return string[]|null An array of DS records for this key or null if no DS records are available. */ - public function getDs() : ?array + public function getDs(): ?array { return $this->ds; } @@ -246,7 +246,7 @@ public function getDs() : ?array * * @return $this The current Cryptokey instance. */ - public function setDs(array $ds) : self + public function setDs(array $ds): self { $this->ds = $ds; @@ -258,7 +258,7 @@ public function setDs(array $ds) : self * * @return string The private key in ISC format. */ - public function getPrivateKey() : string + public function getPrivateKey(): string { return $this->privateKey; } @@ -270,7 +270,7 @@ public function getPrivateKey() : string * * @return $this The current Cryptokey instance. */ - public function setPrivateKey(string $privateKey) : self + public function setPrivateKey(string $privateKey): self { $this->privateKey = $privateKey; @@ -282,7 +282,7 @@ public function setPrivateKey(string $privateKey) : self * * @return string The name of the algorithm of the key, should be a mnemonic. */ - public function getAlgorithm() : string + public function getAlgorithm(): string { return $this->algorithm; } @@ -294,7 +294,7 @@ public function getAlgorithm() : string * * @return $this The current Cryptokey instance. */ - public function setAlgorithm(string $algorithm) : self + public function setAlgorithm(string $algorithm): self { $this->algorithm = $algorithm; @@ -306,7 +306,7 @@ public function setAlgorithm(string $algorithm) : self * * @return int The size of the key. */ - public function getBits() : int + public function getBits(): int { return $this->bits; } @@ -318,7 +318,7 @@ public function getBits() : int * * @return $this The current Cryptokey instance. */ - public function setBits(int $bits) : self + public function setBits(int $bits): self { $this->bits = $bits; diff --git a/src/Resources/Record.php b/src/Resources/Record.php index 86054af..7af5b08 100644 --- a/src/Resources/Record.php +++ b/src/Resources/Record.php @@ -40,7 +40,7 @@ public function __construct(?string $content = null) * * @return string The content. */ - public function getContent() : string + public function getContent(): string { return $this->content; } @@ -52,7 +52,7 @@ public function getContent() : string * * @return $this The current Record instance. */ - public function setContent(string $content) : self + public function setContent(string $content): self { $this->content = $content; @@ -64,7 +64,7 @@ public function setContent(string $content) : self * * @return bool Whether or not this record is disabled. */ - public function isDisabled() : bool + public function isDisabled(): bool { return $this->disabled ?? false; } @@ -76,7 +76,7 @@ public function isDisabled() : bool * * @return $this The current Record instance. */ - public function setDisabled(bool $disabled) : self + public function setDisabled(bool $disabled): self { $this->disabled = $disabled; @@ -88,7 +88,7 @@ public function setDisabled(bool $disabled) : self * * @return bool Whether or not a PTR record must be created when PATCH/POST this record. */ - public function isSetPtr() : bool + public function isSetPtr(): bool { return $this->setPtr ?? false; } @@ -100,7 +100,7 @@ public function isSetPtr() : bool * * @return $this The current Record instance. */ - public function setSetPtr(bool $setPtr) : self + public function setSetPtr(bool $setPtr): self { $this->setPtr = $setPtr; diff --git a/src/Resources/ResourceRecord.php b/src/Resources/ResourceRecord.php index 635cf84..7d87e85 100644 --- a/src/Resources/ResourceRecord.php +++ b/src/Resources/ResourceRecord.php @@ -67,7 +67,7 @@ class ResourceRecord * * @return $this The current resource record. */ - public function setZone(Zone $zone) : self + public function setZone(Zone $zone): self { $this->zone = $zone; @@ -79,7 +79,7 @@ public function setZone(Zone $zone) : self * * @return bool True when successful. */ - public function save() : bool + public function save(): bool { return $this->zone->patch([$this]); } @@ -89,7 +89,7 @@ public function save() : bool * * @return bool True when successful. */ - public function delete() : bool + public function delete(): bool { $this->setChangeType('DELETE'); @@ -103,7 +103,7 @@ public function delete() : bool * * @return $this The current resource record instance. */ - public function setApiResponse(array $rrset) : self + public function setApiResponse(array $rrset): self { if (isset($rrset['comments']) && is_array($rrset['comments'])) { foreach ($rrset['comments'] as $record) { @@ -150,7 +150,7 @@ public function setApiResponse(array $rrset) : self * * @return $this The current resource record instance. */ - public function addComment(Comment $comment) : self + public function addComment(Comment $comment): self { $this->comments[] = $comment; @@ -164,7 +164,7 @@ public function addComment(Comment $comment) : self * * @return $this The current resource record instance. */ - public function addRecord(Record $record) : self + public function addRecord(Record $record): self { $this->records[] = $record; @@ -176,7 +176,7 @@ public function addRecord(Record $record) : self * * @return string The current set change type. */ - public function getChangeType() : string + public function getChangeType(): string { return $this->changeType; } @@ -190,7 +190,7 @@ public function getChangeType() : string * * @return $this The current ResourceRecord instance. */ - public function setChangeType(string $changeType) : self + public function setChangeType(string $changeType): self { $changeType = strtoupper($changeType); if ($changeType === 'REPLACE' || $changeType === 'DELETE') { @@ -209,7 +209,7 @@ public function setChangeType(string $changeType) : self * * @return Comment[] The comments. */ - public function getComments() : array + public function getComments(): array { return $this->comments; } @@ -221,7 +221,7 @@ public function getComments() : array * * @return $this The current ResourceRecord instance. */ - public function setComments(array $comments) : self + public function setComments(array $comments): self { $this->comments = $comments; @@ -233,7 +233,7 @@ public function setComments(array $comments) : self * * @return string The name. */ - public function getName() : string + public function getName(): string { return $this->name; } @@ -245,7 +245,7 @@ public function getName() : string * * @return $this The current ResourceRecord instance. */ - public function setName(string $name) : self + public function setName(string $name): self { $this->name = $name; @@ -257,7 +257,7 @@ public function setName(string $name) : self * * @return Record[] The records. */ - public function getRecords() : array + public function getRecords(): array { return $this->records; } @@ -269,7 +269,7 @@ public function getRecords() : array * * @return $this The current resource record instance. */ - public function setRecord($record) : self + public function setRecord($record): self { return $this->setRecords([$record]); } @@ -281,7 +281,7 @@ public function setRecord($record) : self * * @return $this The current ResourceRecord instance. */ - public function setRecords(array $records) : self + public function setRecords(array $records): self { $recordList = []; @@ -303,7 +303,7 @@ public function setRecords(array $records) : self * * @return int The TTL. */ - public function getTtl() : int + public function getTtl(): int { return $this->ttl; } @@ -315,7 +315,7 @@ public function getTtl() : int * * @return $this The current ResourceRecord instance. */ - public function setTtl(int $ttl) : self + public function setTtl(int $ttl): self { $this->ttl = $ttl; @@ -327,7 +327,7 @@ public function setTtl(int $ttl) : self * * @return string The resource record type. */ - public function getType() : string + public function getType(): string { return $this->type; } @@ -343,7 +343,7 @@ public function getType() : string * * @return $this The current ResourceRecord instance. */ - public function setType(string $type) : self + public function setType(string $type): self { $type = strtoupper($type); diff --git a/src/Resources/ResourceSet.php b/src/Resources/ResourceSet.php index 92edabd..06ed07d 100644 --- a/src/Resources/ResourceSet.php +++ b/src/Resources/ResourceSet.php @@ -44,7 +44,7 @@ public function __construct(Zone $zone, ?array $resourceRecords = null) * * @return ResourceSet The current ResourceSet instance. */ - public function addResource(ResourceRecord $resourceRecord) : self + public function addResource(ResourceRecord $resourceRecord): self { $this->resourceRecords[] = $resourceRecord; @@ -56,7 +56,7 @@ public function addResource(ResourceRecord $resourceRecord) : self * * @return int The number of resource records. */ - public function count() : int + public function count(): int { return count($this->resourceRecords); } @@ -66,7 +66,7 @@ public function count() : int * * @return bool True when there are resource records in this collection. */ - public function isNotEmpty() : bool + public function isNotEmpty(): bool { return !$this->isEmpty(); } @@ -76,7 +76,7 @@ public function isNotEmpty() : bool * * @return bool True when there are no resource records in this collection. */ - public function isEmpty() : bool + public function isEmpty(): bool { return empty($this->resourceRecords); } @@ -88,7 +88,7 @@ public function isEmpty() : bool * * @return ResourceSet The current ResourceSet instance. */ - public function map(Closure $closure) : self + public function map(Closure $closure): self { foreach ($this->resourceRecords as $index => $resource) { $this->resourceRecords[$index] = $closure($resource, $index); @@ -102,7 +102,7 @@ public function map(Closure $closure) : self * * @return bool True when the resource records are deleted. */ - public function delete() : bool + public function delete(): bool { foreach ($this->resourceRecords as $index => $resource) { $this->resourceRecords[$index] = $resource->setChangeType('DELETE'); @@ -116,7 +116,7 @@ public function delete() : bool * * @return bool True when the resource records are saved. */ - public function save() : bool + public function save(): bool { return $this->zone->patch($this->resourceRecords); } @@ -124,7 +124,7 @@ public function save() : bool /** * {@inheritdoc} */ - public function getIterator() : ArrayIterator + public function getIterator(): ArrayIterator { return new ArrayIterator($this->resourceRecords); } @@ -132,7 +132,7 @@ public function getIterator() : ArrayIterator /** * {@inheritdoc} */ - public function offsetExists($offset) : bool + public function offsetExists($offset): bool { return isset($this->resourceRecords[$offset]); } @@ -148,7 +148,7 @@ public function offsetGet($offset) /** * {@inheritdoc} */ - public function offsetSet($offset, $value) : void + public function offsetSet($offset, $value): void { $this->resourceRecords[$offset] = $value; } @@ -156,7 +156,7 @@ public function offsetSet($offset, $value) : void /** * {@inheritdoc} */ - public function offsetUnset($offset) : void + public function offsetUnset($offset): void { unset($this->resourceRecords[$offset]); } diff --git a/src/Resources/Zone.php b/src/Resources/Zone.php index f90f083..3b88fd3 100644 --- a/src/Resources/Zone.php +++ b/src/Resources/Zone.php @@ -49,7 +49,12 @@ class Zone /** * @var string The SOA-EDIT-API metadata item. */ - private $soaEditApi = 'INCEPTION-INCREMENT'; + private $soaEdit = 'INCEPTION-INCREMENT'; + + /** + * @var string The SOA-EDIT metadata item. + */ + private $soaEditApi = 'DEFAULT'; /** * @var bool Whether or not the zone will be rectified on data changes via the API. @@ -74,7 +79,7 @@ class Zone * * @return Zone The current zone instance. */ - public function setApiResponse(array $data) : self + public function setApiResponse(array $data): self { $this->name = $data['name']; $this->kind = $data['kind']; @@ -83,6 +88,7 @@ public function setApiResponse(array $data) : self $this->masters = $data['masters']; $this->dnssec = $data['dnssec']; $this->nsec3param = !empty($data['nsec3param']) ? $data['nsec3param'] : null; + $this->soaEdit = !empty($data['soa_edit']) ? $data['soa_edit'] : null; $this->soaEditApi = !empty($data['soa_edit_api']) ? $data['soa_edit_api'] : null; $this->apiRectify = $data['api_rectify']; $this->account = !empty($data['account']) ? $data['account'] : null; @@ -109,7 +115,7 @@ public function setApiResponse(array $data) : self * * @return string The zone name. */ - public function getName() : string + public function getName(): string { return $this->name; } @@ -119,7 +125,7 @@ public function getName() : string * * @return string The zone kind. */ - public function getKind() : string + public function getKind(): string { return $this->kind; } @@ -129,7 +135,7 @@ public function getKind() : string * * @return int The SOA serial number. */ - public function getSerial() : int + public function getSerial(): int { return $this->serial; } @@ -139,7 +145,7 @@ public function getSerial() : int * * @return int The SOA serial notifications have been sent out for. */ - public function getNotifiedSerial() : int + public function getNotifiedSerial(): int { return $this->notifiedSerial; } @@ -149,7 +155,7 @@ public function getNotifiedSerial() : int * * @return string[] List of IP addresses. */ - public function getMasters() : array + public function getMasters(): array { return $this->masters; } @@ -159,7 +165,7 @@ public function getMasters() : array * * @return bool Whether or not this zone is DNSSEC signed. */ - public function hasDnssec() : bool + public function hasDnssec(): bool { return $this->dnssec; } @@ -169,7 +175,7 @@ public function hasDnssec() : bool * * @return string|null The NSEC3PARAM value or null. */ - public function getNsec3param() : ?string + public function getNsec3param(): ?string { return $this->nsec3param; } @@ -179,17 +185,27 @@ public function getNsec3param() : ?string * * @return string|null The SOA-EDIT-API metadata item or null */ - public function getSoaEditApi() : ?string + public function getSoaEditApi(): ?string { return $this->soaEditApi; } + /** + * Get the SOA-EDIT metadata item. + * + * @return string|null The SOA-EDIT metadata item or null + */ + public function getSoaEdit(): ?string + { + return $this->soaEdit; + } + /** * Whether or not this zone is automatically rectified by the API. * * @return bool Whether or not this zone is automatically rectified by the API. */ - public function hasAutoRectify() : bool + public function hasAutoRectify(): bool { return $this->apiRectify; } @@ -200,7 +216,7 @@ public function hasAutoRectify() : bool * * @return string[] The nameservers. */ - public function getNameservers() : array + public function getNameservers(): array { return $this->nameservers; } @@ -210,7 +226,7 @@ public function getNameservers() : array * * @return string|null The account name or null. */ - public function getAccount() : ?string + public function getAccount(): ?string { return $this->account; } @@ -222,7 +238,7 @@ public function getAccount() : ?string * * @return Zone The current Zone instance. */ - public function setName(string $name) : self + public function setName(string $name): self { $this->name = $name; @@ -238,13 +254,13 @@ public function setName(string $name) : self * * @return Zone The current Zone instance. */ - public function setKind(string $kind) : self + public function setKind(string $kind): self { $kind = ucfirst($kind); $allowed = ['Native', 'Master', 'Slave']; if (!in_array($kind, $allowed, true)) { - throw new InvalidKindType(sprintf('Kind must be either %s. (%s given)', implode($allowed, ', '), $kind)); + throw new InvalidKindType(sprintf('Kind must be either %s. (%s given)', implode(', ', $allowed), $kind)); } $this->kind = $kind; @@ -259,7 +275,7 @@ public function setKind(string $kind) : self * * @return Zone The current Zone instance. */ - public function setSerial(int $serial) : self + public function setSerial(int $serial): self { $this->serial = $serial; @@ -273,7 +289,7 @@ public function setSerial(int $serial) : self * * @return Zone The current Zone instance. */ - public function setNotifiedSerial(int $notifiedSerial) : self + public function setNotifiedSerial(int $notifiedSerial): self { $this->notifiedSerial = $notifiedSerial; @@ -289,7 +305,7 @@ public function setNotifiedSerial(int $notifiedSerial) : self * * @return Zone The current Zone instance. */ - public function setMasters(array $masters) : self + public function setMasters(array $masters): self { if ($this->kind !== 'Slave') { throw new InvalidKindType(sprintf('Only "Slave" kind zones can set masters, not "%".', $this->kind)); @@ -307,7 +323,7 @@ public function setMasters(array $masters) : self * * @return Zone The current Zone instance. */ - public function setDnssec(bool $dnssec) : self + public function setDnssec(bool $dnssec): self { $this->dnssec = $dnssec; @@ -326,10 +342,10 @@ public function setDnssec(bool $dnssec) : self * * @return Zone The current Zone instance. */ - public function setNsec3param(string $nsec3param) : self + public function setNsec3param(string $nsec3param): self { // Validate the nsec3param. - list($algorithm, $flags, $iterations, $salt) = explode(' ', $nsec3param); + [$algorithm, $flags, $iterations, $salt] = explode(' ', $nsec3param); if ((int) $algorithm !== 1) { throw new InvalidNsec3Param('The nsec3param hash algorithm parameter must be set to 1.'); @@ -350,7 +366,7 @@ public function setNsec3param(string $nsec3param) : self } /** - * The SOA edit API kind, one of "INCREMENT-WEEKS", "INCEPTION-EPOCH", "INCEPTION-INCREMENT", "EPOCH" or "NONE". + * The SOA edit API kind. * * @param string $soaEditApi The SOA edit API value. * @@ -358,14 +374,14 @@ public function setNsec3param(string $nsec3param) : self * * @return Zone The current Zone instance. */ - public function setSoaEditApi(string $soaEditApi) : self + public function setSoaEditApi(string $soaEditApi): self { $soaEditApi = strtoupper($soaEditApi); - $allowed = ['INCREMENT-WEEKS', 'INCEPTION-EPOCH', 'INCEPTION-INCREMENT', 'EPOCH', 'NONE']; + $allowed = ['DEFAULT', 'INCREASE', 'EPOCH', 'SOA-EDIT', 'SOA-EDIT-INCREASE']; if (!in_array($soaEditApi, $allowed, true)) { throw new InvalidSoaEditType( - sprintf('Kind must be either %s. (%s given)', implode($allowed, ', '), $soaEditApi) + sprintf('Kind must be either %s. (%s given)', implode(', ', $allowed), $soaEditApi) ); } @@ -374,6 +390,31 @@ public function setSoaEditApi(string $soaEditApi) : self return $this; } + /** + * The SOA edit kind, one of "INCREMENT-WEEKS", "INCEPTION-EPOCH", "INCEPTION-INCREMENT", "EPOCH" or "NONE". + * + * @param string $soaEdit The SOA edit value. + * + * @throws InvalidSoaEditType If a kind is given that is not allowed. + * + * @return Zone The current Zone instance. + */ + public function setSoaEdit(string $soaEdit): self + { + $soaEdit = strtoupper($soaEdit); + $allowed = ['INCREMENT-WEEKS', 'INCEPTION-EPOCH', 'INCEPTION-INCREMENT', 'EPOCH', 'NONE']; + + if (!in_array($soaEdit, $allowed, true)) { + throw new InvalidSoaEditType( + sprintf('Kind must be either %s. (%s given)', implode(', ', $allowed), $soaEdit) + ); + } + + $this->soaEdit = $soaEdit; + + return $this; + } + /** * Set API-RECTIFY to true or false. * @@ -381,7 +422,7 @@ public function setSoaEditApi(string $soaEditApi) : self * * @return Zone The current Zone instance. */ - public function setApiRectify(bool $apiRectify) : self + public function setApiRectify(bool $apiRectify): self { $this->apiRectify = $apiRectify; @@ -396,7 +437,7 @@ public function setApiRectify(bool $apiRectify) : self * * @return Zone The current Zone instance. */ - public function setNameservers(array $nameservers) : self + public function setNameservers(array $nameservers): self { $this->nameservers = $nameservers; @@ -410,7 +451,7 @@ public function setNameservers(array $nameservers) : self * * @return Zone The current Zone instance. */ - public function setAccount(string $account) : self + public function setAccount(string $account): self { $this->account = $account; diff --git a/src/Transformers/CreateZoneTransformer.php b/src/Transformers/CreateZoneTransformer.php index e7aecbd..33debba 100644 --- a/src/Transformers/CreateZoneTransformer.php +++ b/src/Transformers/CreateZoneTransformer.php @@ -14,6 +14,7 @@ public function transform() 'kind' => $this->data->getKind(), 'dnssec' => $this->data->hasDnssec(), 'api_rectify' => $this->data->hasAutoRectify(), + 'soa_edit' => $this->data->getSoaEdit(), 'soa_edit_api' => $this->data->getSoaEditApi(), 'masters' => $this->data->getMasters(), 'nameservers' => $this->data->getNameservers(), diff --git a/src/Transformers/Transformer.php b/src/Transformers/Transformer.php index a2e37fe..ba5e7bb 100644 --- a/src/Transformers/Transformer.php +++ b/src/Transformers/Transformer.php @@ -28,7 +28,7 @@ public function __construct($data = null) * * @return $this The current transformer instance. */ - public function setData($data) : self + public function setData($data): self { $this->data = $data; diff --git a/src/Zone.php b/src/Zone.php index 30183fc..4afbed8 100644 --- a/src/Zone.php +++ b/src/Zone.php @@ -25,7 +25,7 @@ class Zone extends AbstractZone * * @return bool True when created. */ - public function create($name, string $type = '', $content = '', int $ttl = 3600) : bool + public function create($name, string $type = '', $content = '', int $ttl = 3600): bool { if (is_array($name)) { foreach ($name as $item) { @@ -45,7 +45,7 @@ public function create($name, string $type = '', $content = '', int $ttl = 3600) * * @return bool True when successful. */ - public function patch(array $resourceRecords) : bool + public function patch(array $resourceRecords): bool { $result = $this->connector->patch($this->getZonePath(), new RRSetTransformer($resourceRecords)); @@ -64,7 +64,7 @@ public function patch(array $resourceRecords) : bool * * @return ResourceSet A ResourceSet containing all the resource records. */ - public function get(?string $recordType = null) : ResourceSet + public function get(?string $recordType = null): ResourceSet { $records = $this->connector->get($this->getZonePath()); $resourceSet = new ResourceSet($this); @@ -87,7 +87,7 @@ public function get(?string $recordType = null) : ResourceSet * * @return ResourceSet A ResourceSet containing all the resource records. */ - public function find(string $resourceRecordName, ?string $recordType = null) : ResourceSet + public function find(string $resourceRecordName, ?string $recordType = null): ResourceSet { $records = $this->get($recordType); @@ -117,7 +117,7 @@ public function find(string $resourceRecordName, ?string $recordType = null) : R * * @return ResourceRecord The constructed ResourceRecord. */ - public function make(string $name, string $type, $content, int $ttl) : ResourceRecord + public function make(string $name, string $type, $content, int $ttl): ResourceRecord { $name = str_replace('@', $this->zone, $name); @@ -152,7 +152,7 @@ public function make(string $name, string $type, $content, int $ttl) : ResourceR * * @return bool True when enabled. */ - public function enableDnssec() : bool + public function enableDnssec(): bool { return $this->setDnssec(true); } @@ -162,7 +162,7 @@ public function enableDnssec() : bool * * @return bool True when disabled. */ - public function disableDnssec() : bool + public function disableDnssec(): bool { return $this->setDnssec(false); } @@ -174,7 +174,7 @@ public function disableDnssec() : bool * * @return bool True when the request succeeded. */ - public function setDnssec(bool $state) : bool + public function setDnssec(bool $state): bool { $result = $this->connector->put($this->getZonePath(), new DnssecTransformer(['dnssec' => $state])); @@ -190,7 +190,7 @@ public function setDnssec(bool $state) : bool * * @return Cryptokey The DNSSEC instance. */ - public function dnssec() : Cryptokey + public function dnssec(): Cryptokey { return new Cryptokey($this->connector, $this->zone); } diff --git a/tests/PowerdnsTest.php b/tests/PowerdnsTest.php index 27e0698..cd5078d 100644 --- a/tests/PowerdnsTest.php +++ b/tests/PowerdnsTest.php @@ -11,7 +11,7 @@ class PowerdnsTest extends TestCase { - public function testConfigViaConstructor() : void + public function testConfigViaConstructor(): void { $powerDns = new Powerdns('test-host', 'test-key', 1234, 'test-server'); $config = $powerDns->getConfig(); @@ -22,7 +22,7 @@ public function testConfigViaConstructor() : void $this->assertSame('test-key', $config['apiKey']); } - public function testConfigViaMethods() : void + public function testConfigViaMethods(): void { $powerDns = new Powerdns(); $powerDns->connect('test-host', 1234, 'test-server'); @@ -35,7 +35,7 @@ public function testConfigViaMethods() : void $this->assertSame('test-key', $config['apiKey']); } - public function testZone() : void + public function testZone(): void { $connector = Mockery::mock(Connector::class); $connector->shouldReceive('post')->withArgs(['zones', Mockery::on(function (CreateZoneTransformer $transformer) { @@ -56,7 +56,7 @@ public function testZone() : void $this->assertTrue($powerDns->deleteZone('test.nl.')); } - public function testListZones() : void + public function testListZones(): void { $connector = Mockery::mock(Connector::class); $connector->shouldReceive('get')->withArgs(['zones'])->once()->andReturn( diff --git a/tests/Resources/CommentTest.php b/tests/Resources/CommentTest.php index e7450a2..89dd366 100644 --- a/tests/Resources/CommentTest.php +++ b/tests/Resources/CommentTest.php @@ -7,7 +7,7 @@ class CommentTest extends TestCase { - public function testSettersAndGetters() : void + public function testSettersAndGetters(): void { $comment = new Comment(); diff --git a/tests/Resources/ResourceRecordTest.php b/tests/Resources/ResourceRecordTest.php index cd2f6d1..9e28259 100644 --- a/tests/Resources/ResourceRecordTest.php +++ b/tests/Resources/ResourceRecordTest.php @@ -13,7 +13,7 @@ class ResourceRecordTest extends TestCase { - public function testSimpleSettersAndGetters() : void + public function testSimpleSettersAndGetters(): void { $resourceRecord = new ResourceRecord(); @@ -23,7 +23,7 @@ public function testSimpleSettersAndGetters() : void $this->assertSame(1234, $resourceRecord->getTtl()); } - public function testZoneRelatedMethods() : void + public function testZoneRelatedMethods(): void { $resourceRecord = new ResourceRecord(); $zone = Mockery::mock(Zone::class); @@ -46,7 +46,7 @@ function (ResourceRecord $updatedResourceRecord) { $this->assertTrue($resourceRecord->delete()); } - public function testSetApiResponse() : void + public function testSetApiResponse(): void { $apiResponse = [ diff --git a/tests/Resources/ResourceSetTest.php b/tests/Resources/ResourceSetTest.php index 091162c..da453b4 100644 --- a/tests/Resources/ResourceSetTest.php +++ b/tests/Resources/ResourceSetTest.php @@ -10,7 +10,7 @@ class ResourceSetTest extends TestCase { - public function testGeneralFunctionality() : void + public function testGeneralFunctionality(): void { $zone = Mockery::mock(Zone::class); @@ -37,7 +37,7 @@ public function testGeneralFunctionality() : void $this->assertSame(1234, $resourceSet[0]->getTtl()); } - public function testSave() : void + public function testSave(): void { $resourceRecord = new ResourceRecord(); @@ -48,7 +48,7 @@ public function testSave() : void $this->assertTrue($resourceSet->save()); } - public function testDelete() : void + public function testDelete(): void { $resourceRecord = Mockery::mock(ResourceRecord::class); $resourceRecord->shouldReceive('setChangeType')->withArgs(['DELETE'])->once()->andReturnSelf(); diff --git a/tests/ZoneTest.php b/tests/ZoneTest.php index afa1539..460e565 100644 --- a/tests/ZoneTest.php +++ b/tests/ZoneTest.php @@ -28,7 +28,7 @@ class ZoneTest extends TestCase ], ]; - public function testCreateSingleResourceRecord() : void + public function testCreateSingleResourceRecord(): void { $connector = Mockery::mock(Connector::class); $connector->shouldReceive('patch')->withArgs(['zones/test.nl.', Mockery::on(function (RRSetTransformer $transformer) { @@ -46,7 +46,7 @@ public function testCreateSingleResourceRecord() : void $zone->create('test', 'A', '127.0.0.1', 10); } - public function testCreateMultipleResourceRecords() : void + public function testCreateMultipleResourceRecords(): void { $connector = Mockery::mock(Connector::class); $connector->shouldReceive('patch')->withArgs(['zones/test.nl.', Mockery::on(function (RRSetTransformer $transformer) { @@ -91,7 +91,7 @@ public function testCreateMultipleResourceRecords() : void ]); } - public function testGetResourceRecords() : void + public function testGetResourceRecords(): void { $connector = Mockery::mock(Connector::class); $connector->shouldReceive('get')->withArgs(['zones/test.nl.'])->once()->andReturn(self::API_RESPONSE); @@ -102,7 +102,7 @@ public function testGetResourceRecords() : void $this->assertSame(1, $zone->get('MX')->count()); } - public function testFindResourceRecords() : void + public function testFindResourceRecords(): void { $connector = Mockery::mock(Connector::class); $connector->shouldReceive('get')->withArgs(['zones/test.nl.'])->once()->andReturn(self::API_RESPONSE); diff --git a/tests/functional/ValidateSOAIncrementTest.php b/tests/functional/ValidateSOAIncrementTest.php new file mode 100644 index 0000000..73b26e3 --- /dev/null +++ b/tests/functional/ValidateSOAIncrementTest.php @@ -0,0 +1,33 @@ +createZone('soa-increment.test', ['ns1.powerdns-php.', 'ns2.powerdns-php.']); + $result = $zone->create('test', RecordType::A, '127.0.0.1', 3600); + + $this->assertTrue($result); + } + + /** + * @depends testCreateSoaIncrementZone + */ + public function testSoaIncrement(): void + { + $powerdns = new Powerdns('127.0.0.1', 'apiKey'); + $zone = $powerdns->zone('soa-increment.test'); + $soaData = $zone->get(RecordType::SOA); + + $expectedSoa = sprintf('ns1.powerdns-php. hostmaster.powerdns-php. %s02 10800 3600 604800 3600', date('Ymd')); + + $this->assertSame($expectedSoa, $soaData[0]->getRecords()[0]->getContent()); + } +}