diff --git a/.github/workflows/draft-release.yaml b/.github/workflows/draft-release.yaml index 9307cba..b6dbce6 100644 --- a/.github/workflows/draft-release.yaml +++ b/.github/workflows/draft-release.yaml @@ -5,7 +5,6 @@ on: push: branches: - master - - develop jobs: update_release_draft: diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml new file mode 100644 index 0000000..94e2c6b --- /dev/null +++ b/.github/workflows/lint.yaml @@ -0,0 +1,24 @@ +--- +name: php-cs-fixer + +on: + push: + branches: + - master + pull_request: + branches: + - master + +jobs: + lint: + name: Run php-cs-fixer + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + ref: ${{ github.head_ref }} + - name: Run php-cs-fixer + uses: docker://oskarstark/php-cs-fixer-ga + - uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: Apply php-cs-fixer changes diff --git a/.gitignore b/.gitignore index 1d570a7..5cc825e 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ /vendor/ composer.lock .phpunit.result.cache +.php-cs-fixer.cache /composer.phar diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php new file mode 100644 index 0000000..4ee99a3 --- /dev/null +++ b/.php-cs-fixer.php @@ -0,0 +1,28 @@ +in(__DIR__.'/src') + ->in(__DIR__.'/tests') + ->in(__DIR__.'/examples'); + +$config = new PhpCsFixer\Config(); + +return $config + ->setRules([ + '@PSR2' => true, + '@Symfony' => true, + '@PhpCsFixer' => true, + 'phpdoc_order' => true, + 'ordered_class_elements' => true, + 'multiline_whitespace_before_semicolons' => false, + 'no_superfluous_phpdoc_tags' => false, + 'phpdoc_annotation_without_dot' => false, + 'phpdoc_types_order' => [ + 'null_adjustment' => 'always_last', + ], + 'yoda_style' => false, + 'ternary_to_null_coalescing' => true, + 'array_syntax' => ['syntax' => 'short'], + 'php_unit_test_class_requires_covers' => false, + ]) + ->setFinder($finder); diff --git a/.styleci.yml b/.styleci.yml deleted file mode 100644 index a77c58a..0000000 --- a/.styleci.yml +++ /dev/null @@ -1,5 +0,0 @@ -preset: recommended - -disabled: - - align_double_arrow - diff --git a/examples/cryptokeys.php b/examples/cryptokeys.php index 5c959f9..63de700 100644 --- a/examples/cryptokeys.php +++ b/examples/cryptokeys.php @@ -1,11 +1,10 @@ setTtl(60); })->save(); -/* - * To delete a specific record from the zone, perform a search followed by a delete: - */ +// To delete a specific record from the zone, perform a search followed by a delete: $zone->find('test3')->delete(); /* diff --git a/examples/new_domain.php b/examples/new_domain.php index 97fbd9d..a82f305 100644 --- a/examples/new_domain.php +++ b/examples/new_domain.php @@ -1,11 +1,10 @@ zone, $path); + return $this->zone; } /** - * Get the canonical name of the zone. Includes the trailing dot (.). + * Get the zone path for API calls. * - * @return string The canonical zone name. + * @param string|null $path The path to append to the zone. + * + * @return string The API zone path. */ - public function getCanonicalName(): string + protected function getZonePath(?string $path = null): string { - return $this->zone; + return sprintf('zones/%s%s', $this->zone, $path); } } diff --git a/src/Connector.php b/src/Connector.php index 143b04f..ecd0d92 100644 --- a/src/Connector.php +++ b/src/Connector.php @@ -107,7 +107,7 @@ public function delete(string $urlPath): array * * @param string $method The method to use for the call. * @param string $urlPath The URL path. - * @param null|string $payload (Optional) The payload to include. + * @param string|null $payload (Optional) The payload to include. * * @throws PowerdnsException When an unknown response is returned. * @throws ValidationException When a validation error is returned. @@ -148,12 +148,17 @@ protected function parseResponse(PsrResponse $response): array case 200: case 201: return $contents ?? []; + break; + case 204: return []; + break; + case 422: throw new ValidationException($contents['error']); + break; } diff --git a/src/Cryptokey.php b/src/Cryptokey.php index 3e24f7e..486f1ca 100644 --- a/src/Cryptokey.php +++ b/src/Cryptokey.php @@ -22,7 +22,7 @@ class Cryptokey extends AbstractZone * Crypto Key constructor. * * @param ConnectorInterface $connector The zone to use. - * @param null|string $canonicalDomain The Powerdns Connector to make calls. + * @param string|null $canonicalDomain The Powerdns Connector to make calls. * @param CryptokeyResource|null $cryptoKeyResource The cryptokey resource class to use for API responses. */ public function __construct( diff --git a/src/Helper.php b/src/Helper.php index 7d2846d..7b39c53 100644 --- a/src/Helper.php +++ b/src/Helper.php @@ -11,9 +11,9 @@ class Helper * Make a new resource record based on the arguments or an array with data. * * @param string $zoneName The zone name for this resource record. - * @param string|array $name The resource record name or an array with the data. + * @param array|string $name The resource record name or an array with the data. * @param string $type The type of the resource record. - * @param string|array $content The content of the resource record. + * @param array|string $content The content of the resource record. * @param int $ttl The TTL. * * @throws Exceptions\InvalidRecordType If the given type is invalid. diff --git a/src/Powerdns.php b/src/Powerdns.php index c5d0ca3..333b7a1 100644 --- a/src/Powerdns.php +++ b/src/Powerdns.php @@ -55,10 +55,10 @@ class Powerdns implements PowerdnsInterface /** * PowerDNS Client constructor. * - * @param null|string $host (optional) The PowerDNS host. Must include protocol (http, https, etc.). - * @param null|string $apiKey (optional) The PowerDNS API key. + * @param string|null $host (optional) The PowerDNS host. Must include protocol (http, https, etc.). + * @param string|null $apiKey (optional) The PowerDNS API key. * @param int|null $port (optional) The PowerDNS API Port. - * @param null|string $server (optional) The PowerDNS server to use. + * @param string|null $server (optional) The PowerDNS server to use. * @param ConnectorInterface|null $connector (optional) The Connector to make calls. */ public function __construct( @@ -212,7 +212,7 @@ public function deleteZone(string $canonicalDomain): bool * * @return Zone[] Array containing the zones * - * @link https://doc.powerdns.com/authoritative/http-api/zone.html#get--servers-server_id-zones + * @see https://doc.powerdns.com/authoritative/http-api/zone.html#get--servers-server_id-zones */ public function listZones(bool $omitDnssecAndEditedSerialFields = false): array { @@ -243,7 +243,7 @@ public function cryptokeys(string $canonicalDomain): Cryptokey * The $statistics and $includeRings parameters are supported in PowerDNS 4.3 and newer. * On older PowerDNS instances these parameters are ignored. * - * @param null|string $statistic Optional name of a specific statistic to get. + * @param string|null $statistic Optional name of a specific statistic to get. * @param bool $includeRings Include ring statistics or not. * * @return array An array with statistics. diff --git a/src/PowerdnsInterface.php b/src/PowerdnsInterface.php index 2e42749..00e3151 100644 --- a/src/PowerdnsInterface.php +++ b/src/PowerdnsInterface.php @@ -75,7 +75,7 @@ public function deleteZone(string $canonicalDomain): bool; * * @return Zone[] Array containing the zones * - * @link https://doc.powerdns.com/authoritative/http-api/zone.html#get--servers-server_id-zones + * @see https://doc.powerdns.com/authoritative/http-api/zone.html#get--servers-server_id-zones */ public function listZones(bool $omitDnssecAndEditedSerialFields = false): array; @@ -95,7 +95,7 @@ public function cryptokeys(string $canonicalDomain): Cryptokey; * The $statistics and $includeRings parameters are supported in PowerDNS 4.3 and newer. * On older PowerDNS instances these parameters are ignored. * - * @param null|string $statistic Optional name of a specific statistic to get. + * @param string|null $statistic Optional name of a specific statistic to get. * @param bool $includeRings Include ring statistics or not. * * @return array An array with statistics. diff --git a/src/Zone.php b/src/Zone.php index f49a4e7..669f3fe 100644 --- a/src/Zone.php +++ b/src/Zone.php @@ -18,9 +18,9 @@ class Zone extends AbstractZone * resource records will be created in a single call to the PowerDNS server. If $name is a string, a single resource * record is created. * - * @param string|mixed[] $name The resource record name. + * @param mixed[]|string $name The resource record name. * @param string $type The type of the resource record. - * @param string|mixed[] $content The content of the resource record. When passing a multidimensional array, + * @param mixed[]|string $content The content of the resource record. When passing a multidimensional array, * multiple records are created for this resource record. * @param int $ttl The TTL. * @@ -85,7 +85,7 @@ public function put(Transformer $transformer): bool * Get all the resource records in the current zone. If $recordType is specified, only get those specific resource * records. * - * @param null|string $recordType (optional) The type of resource record. + * @param string|null $recordType (optional) The type of resource record. * * @return ResourceSet A ResourceSet containing all the resource records. */ @@ -107,7 +107,7 @@ public function get(?string $recordType = null): ResourceSet * specified, only get those specific resource records. * * @param string $resourceRecordName The name of the resource record. - * @param null|string $recordType (optional) The type of resource record. + * @param string|null $recordType (optional) The type of resource record. * * @return ResourceSet A ResourceSet containing all the resource records. */ @@ -119,8 +119,8 @@ public function find(string $resourceRecordName, ?string $recordType = null): Re foreach ($records as $record) { if ( - $record->getName() === $resourceRecordName || - $record->getName() === sprintf('%s.%s', $resourceRecordName, $this->zone) + $record->getName() === $resourceRecordName + || $record->getName() === sprintf('%s.%s', $resourceRecordName, $this->zone) ) { $foundResources->addResource($record); } diff --git a/tests/ConnectorTest.php b/tests/ConnectorTest.php index d47b4f8..ac4beb6 100644 --- a/tests/ConnectorTest.php +++ b/tests/ConnectorTest.php @@ -15,6 +15,9 @@ use PHPUnit\Framework\TestCase; use Psr\Log\NullLogger; +/** + * @internal + */ class ConnectorTest extends TestCase { public function testApiCallsAreExecuted() diff --git a/tests/HelperTest.php b/tests/HelperTest.php index ede5648..d24d388 100644 --- a/tests/HelperTest.php +++ b/tests/HelperTest.php @@ -6,6 +6,9 @@ use Exonet\Powerdns\RecordType; use PHPUnit\Framework\TestCase; +/** + * @internal + */ class HelperTest extends TestCase { public function testWithArguments(): void diff --git a/tests/PowerdnsTest.php b/tests/PowerdnsTest.php index dd61787..734181f 100644 --- a/tests/PowerdnsTest.php +++ b/tests/PowerdnsTest.php @@ -9,6 +9,9 @@ use Mockery; use PHPUnit\Framework\TestCase; +/** + * @internal + */ class PowerdnsTest extends TestCase { public function testConfigViaConstructor(): void diff --git a/tests/Resources/CommentTest.php b/tests/Resources/CommentTest.php index 89dd366..d29eb31 100644 --- a/tests/Resources/CommentTest.php +++ b/tests/Resources/CommentTest.php @@ -5,6 +5,9 @@ use Exonet\Powerdns\Resources\Comment; use PHPUnit\Framework\TestCase; +/** + * @internal + */ class CommentTest extends TestCase { public function testSettersAndGetters(): void diff --git a/tests/Resources/RecordTest.php b/tests/Resources/RecordTest.php index a669ba7..04fe8a3 100644 --- a/tests/Resources/RecordTest.php +++ b/tests/Resources/RecordTest.php @@ -5,6 +5,9 @@ use Exonet\Powerdns\Resources\Record; use PHPUnit\Framework\TestCase; +/** + * @internal + */ class RecordTest extends TestCase { public function testSettersAndGetters() diff --git a/tests/Resources/ResourceRecordTest.php b/tests/Resources/ResourceRecordTest.php index 9e28259..f4cd7de 100644 --- a/tests/Resources/ResourceRecordTest.php +++ b/tests/Resources/ResourceRecordTest.php @@ -11,6 +11,9 @@ use Mockery; use PHPUnit\Framework\TestCase; +/** + * @internal + */ class ResourceRecordTest extends TestCase { public function testSimpleSettersAndGetters(): void diff --git a/tests/Resources/ResourceSetTest.php b/tests/Resources/ResourceSetTest.php index da453b4..4a703ad 100644 --- a/tests/Resources/ResourceSetTest.php +++ b/tests/Resources/ResourceSetTest.php @@ -8,6 +8,9 @@ use Mockery; use PHPUnit\Framework\TestCase; +/** + * @internal + */ class ResourceSetTest extends TestCase { public function testGeneralFunctionality(): void diff --git a/tests/Resources/ZoneTest.php b/tests/Resources/ZoneTest.php index 72f8f13..8bdafff 100644 --- a/tests/Resources/ZoneTest.php +++ b/tests/Resources/ZoneTest.php @@ -8,6 +8,9 @@ use Exonet\Powerdns\Resources\Zone; use PHPUnit\Framework\TestCase; +/** + * @internal + */ class ZoneTest extends TestCase { public function testSetApiResponse(): void diff --git a/tests/ZoneTest.php b/tests/ZoneTest.php index f6633d4..01a9bbe 100644 --- a/tests/ZoneTest.php +++ b/tests/ZoneTest.php @@ -9,6 +9,9 @@ use Mockery; use PHPUnit\Framework\TestCase; +/** + * @internal + */ class ZoneTest extends TestCase { public const API_RESPONSE = [ diff --git a/tests/functional/AdvancedZoneCreationTest.php b/tests/functional/AdvancedZoneCreationTest.php index 12a51fb..3dbda39 100644 --- a/tests/functional/AdvancedZoneCreationTest.php +++ b/tests/functional/AdvancedZoneCreationTest.php @@ -4,6 +4,9 @@ use Exonet\Powerdns\Resources\Zone as ZoneResource; +/** + * @internal + */ class AdvancedZoneCreationTest extends FunctionalTestCase { public function testCreateSoaIncrementZone(): void diff --git a/tests/functional/GitHub38Test.php b/tests/functional/GitHub38Test.php index bd58301..036be9f 100644 --- a/tests/functional/GitHub38Test.php +++ b/tests/functional/GitHub38Test.php @@ -4,6 +4,8 @@ /** * Test scenario for https://github.com/exonet/powerdns-php/issues/38. + * + * @internal */ class GitHub38Test extends FunctionalTestCase { diff --git a/tests/functional/ValidateSOAIncrementTest.php b/tests/functional/ValidateSOAIncrementTest.php index c3ccfec..fa26282 100644 --- a/tests/functional/ValidateSOAIncrementTest.php +++ b/tests/functional/ValidateSOAIncrementTest.php @@ -4,6 +4,9 @@ use Exonet\Powerdns\RecordType; +/** + * @internal + */ class ValidateSOAIncrementTest extends FunctionalTestCase { public function testCreateSoaIncrementZone(): void diff --git a/tests/functional/ZoneRecordsTest.php b/tests/functional/ZoneRecordsTest.php index fe62098..573efa1 100644 --- a/tests/functional/ZoneRecordsTest.php +++ b/tests/functional/ZoneRecordsTest.php @@ -8,6 +8,9 @@ use Exonet\Powerdns\Resources\ResourceSet; use Exonet\Powerdns\Resources\Zone as ZoneResource; +/** + * @internal + */ class ZoneRecordsTest extends FunctionalTestCase { use ArraySubsetAsserts; @@ -30,6 +33,12 @@ class ZoneRecordsTest extends FunctionalTestCase ['name' => '@', 'type' => RecordType::A, 'content' => '127.0.0.1', 'ttl' => 60], ]; + protected function setUp(): void + { + parent::setUp(); + $this->canonicalName = 'zone-with-records.'.time().'.test.'; + } + public function testCreateZoneFromResource(): void { // Create a new zone resource. @@ -61,12 +70,6 @@ public function testCustomSoa(): void self::assertSame('ns1.test. hostmaster.test. '.date('Ymd').'02 10800 3605 604800 3600', $soaRecord); } - protected function setUp(): void - { - parent::setUp(); - $this->canonicalName = 'zone-with-records.'.time().'.test.'; - } - private function validateResourceSet(ResourceSet $resourceSet): void { $createdRecords = []; diff --git a/tests/functional/ZoneTest.php b/tests/functional/ZoneTest.php index 5b20410..a0f8620 100644 --- a/tests/functional/ZoneTest.php +++ b/tests/functional/ZoneTest.php @@ -2,6 +2,9 @@ namespace Exonet\Powerdns\tests\functional; +/** + * @internal + */ class ZoneTest extends FunctionalTestCase { /**