From 9fada1398d3779d081bba307227b00e2fffda2b8 Mon Sep 17 00:00:00 2001 From: Bennet Gallein Date: Mon, 13 May 2024 19:38:52 +0200 Subject: [PATCH] chore: formatting --- src/Resources/TSIGKey.php | 36 ++++++--- src/TSIGKey.php | 57 ++++++++------ src/Transformers/TSIGKeyCreateTransformer.php | 14 ++-- .../TSIGKeyUpdateAlgorithmTransformer.php | 6 +- .../TSIGKeyUpdateKeyTransformer.php | 6 +- .../TSIGKeyUpdateNameTransformer.php | 6 +- src/Transformers/Transformer.php | 9 ++- tests/functional/TSIGKeysTest.php | 77 +++++++++---------- 8 files changed, 120 insertions(+), 91 deletions(-) diff --git a/src/Resources/TSIGKey.php b/src/Resources/TSIGKey.php index 6de7ed7..dd92d2d 100644 --- a/src/Resources/TSIGKey.php +++ b/src/Resources/TSIGKey.php @@ -4,7 +4,8 @@ namespace Exonet\Powerdns\Resources; -class TSIGKey { +class TSIGKey +{ /** * The name of the key. * @@ -45,7 +46,8 @@ class TSIGKey { * * @param string $content Optional content to set. */ - public function __construct(?array $content = null) { + public function __construct(?array $content = null) + { if ($content) { $this->setName($content['name'] ?? ''); $this->setId($content['id'] ?? ''); @@ -60,7 +62,8 @@ public function __construct(?array $content = null) { * * @return string */ - public function getType() { + public function getType() + { return $this->type; } @@ -71,7 +74,8 @@ public function getType() { * * @return self */ - public function setType(string $type) { + public function setType(string $type) + { $this->type = $type; return $this; @@ -82,7 +86,8 @@ public function setType(string $type) { * * @return string */ - public function getKey() { + public function getKey() + { return $this->key; } @@ -93,7 +98,8 @@ public function getKey() { * * @return self */ - public function setKey(string $key) { + public function setKey(string $key) + { $this->key = $key; return $this; @@ -104,7 +110,8 @@ public function setKey(string $key) { * * @return string */ - public function getAlgorithm() { + public function getAlgorithm() + { return $this->algorithm; } @@ -115,7 +122,8 @@ public function getAlgorithm() { * * @return self */ - public function setAlgorithm(string $algorithm) { + public function setAlgorithm(string $algorithm) + { $this->algorithm = $algorithm; return $this; @@ -126,7 +134,8 @@ public function setAlgorithm(string $algorithm) { * * @return string */ - public function getId() { + public function getId() + { return $this->id; } @@ -137,7 +146,8 @@ public function getId() { * * @return self */ - public function setId(string $id) { + public function setId(string $id) + { $this->id = $id; return $this; @@ -148,7 +158,8 @@ public function setId(string $id) { * * @return string */ - public function getName() { + public function getName() + { return $this->name; } @@ -159,7 +170,8 @@ public function getName() { * * @return self */ - public function setName(string $name) { + public function setName(string $name) + { $this->name = $name; return $this; diff --git a/src/TSIGKey.php b/src/TSIGKey.php index 5075d61..67e6d7d 100644 --- a/src/TSIGKey.php +++ b/src/TSIGKey.php @@ -9,20 +9,21 @@ use Exonet\Powerdns\Transformers\TSIGKeyUpdateKeyTransformer; use Exonet\Powerdns\Transformers\TSIGKeyUpdateNameTransformer; -class TSIGKey { - +class TSIGKey +{ /** - * - * @var ConnectorInterface $connector + * @var ConnectorInterface */ - private $connector = null; + private $connector; + /** - * get a new instance of the tsig interface + * get a new instance of the tsig interface. * * @param ConnectorInterface $connector */ public function __construct( - ConnectorInterface $connector) { + ConnectorInterface $connector + ) { $this->connector = $connector; } @@ -31,7 +32,8 @@ public function __construct( * * @return TSIGKeySet The meta data set. */ - public function list(): TSIGKeySet { + public function list(): TSIGKeySet + { $items = $this->connector->get('tsigkeys'); $resultSet = new TSIGKeySet(); @@ -49,8 +51,9 @@ public function list(): TSIGKeySet { * * @return TSIGKeyResource The meta data set. */ - public function get(string $id): TSIGKeyResource { - $item = $this->connector->get('tsigkeys/' . $id); + public function get(string $id): TSIGKeyResource + { + $item = $this->connector->get('tsigkeys/'.$id); return new TSIGKeyResource($item); } @@ -62,43 +65,52 @@ public function get(string $id): TSIGKeyResource { * * @return TSIGKeyResource The created key data. */ - public function create(TSIGKeyResource $data): TSIGKeyResource { + public function create(TSIGKeyResource $data): TSIGKeyResource + { $response = $this->connector->post('tsigkeys', new TSIGKeyCreateTransformer($data)); return new TSIGKeyResource($response); } /** - * Update an existing TSIGKey and reset the algorithm + * Update an existing TSIGKey and reset the algorithm. * * @param TSIGKeyResource $resource The key data item to update. * * @return TSIGKeyResource the updated key resource. */ - public function updateAlgorithm(TSIGKeyResource $resource): TSIGKeyResource { - $response = $this->connector->put('tsigkeys/' . $resource->getId(), new TSIGKeyUpdateAlgorithmTransformer($resource)); + public function updateAlgorithm(TSIGKeyResource $resource): TSIGKeyResource + { + $response = $this->connector->put('tsigkeys/'.$resource->getId(), new TSIGKeyUpdateAlgorithmTransformer($resource)); + return new TSIGKeyResource($response); } /** - * update the key of a tsigkey + * update the key of a tsigkey. * * @param TSIGKeyResource $resource + * * @return TSIGKeyResource */ - public function updateKey(TSIGKeyResource $resource): TSIGKeyResource { - $response = $this->connector->put('tsigkeys/' . $resource->getId(), new TSIGKeyUpdateKeyTransformer($resource)); + public function updateKey(TSIGKeyResource $resource): TSIGKeyResource + { + $response = $this->connector->put('tsigkeys/'.$resource->getId(), new TSIGKeyUpdateKeyTransformer($resource)); + return new TSIGKeyResource($response); } /** - * change the name of a tsigkey, this will change remove the old key and add a new one + * change the name of a tsigkey, this will change remove the old key and add a new one. * * @param TSIGKeyResource $resource + * * @return TSIGKeyResource */ - public function updateName(TSIGKeyResource $resource): TSIGKeyResource { - $response = $this->connector->put('tsigkeys/' . $resource->getId(), new TSIGKeyUpdateNameTransformer($resource)); + public function updateName(TSIGKeyResource $resource): TSIGKeyResource + { + $response = $this->connector->put('tsigkeys/'.$resource->getId(), new TSIGKeyUpdateNameTransformer($resource)); + return new TSIGKeyResource($response); } @@ -109,8 +121,9 @@ public function updateName(TSIGKeyResource $resource): TSIGKeyResource { * * @return bool True if the delete was successful. */ - public function delete(TSIGKeyResource $key): bool { - $response = $this->connector->delete('tsigkeys/' . $key->getId()); + public function delete(TSIGKeyResource $key): bool + { + $response = $this->connector->delete('tsigkeys/'.$key->getId()); // If the response is empty, everything is fine. return empty($response); diff --git a/src/Transformers/TSIGKeyCreateTransformer.php b/src/Transformers/TSIGKeyCreateTransformer.php index 5ac9bcd..1d11fae 100644 --- a/src/Transformers/TSIGKeyCreateTransformer.php +++ b/src/Transformers/TSIGKeyCreateTransformer.php @@ -2,17 +2,19 @@ namespace Exonet\Powerdns\Transformers; -class TSIGKeyCreateTransformer extends Transformer { +class TSIGKeyCreateTransformer extends Transformer +{ /** * {@inheritdoc} */ - public function transform() { + public function transform() + { return (object) [ - 'name' => $this->data->getName(), - 'id' => $this->data->getId(), + 'name' => $this->data->getName(), + 'id' => $this->data->getId(), 'algorithm' => $this->data->getAlgorithm(), - 'key' => $this->data->getKey(), - 'type' => $this->data->getType(), + 'key' => $this->data->getKey(), + 'type' => $this->data->getType(), ]; } } diff --git a/src/Transformers/TSIGKeyUpdateAlgorithmTransformer.php b/src/Transformers/TSIGKeyUpdateAlgorithmTransformer.php index 90e1c50..2c434d4 100644 --- a/src/Transformers/TSIGKeyUpdateAlgorithmTransformer.php +++ b/src/Transformers/TSIGKeyUpdateAlgorithmTransformer.php @@ -2,11 +2,13 @@ namespace Exonet\Powerdns\Transformers; -class TSIGKeyUpdateAlgorithmTransformer extends Transformer { +class TSIGKeyUpdateAlgorithmTransformer extends Transformer +{ /** * {@inheritdoc} */ - public function transform() { + public function transform() + { return (object) [ 'algorithm' => $this->data->getAlgorithm(), ]; diff --git a/src/Transformers/TSIGKeyUpdateKeyTransformer.php b/src/Transformers/TSIGKeyUpdateKeyTransformer.php index 4031059..3d3d4c8 100644 --- a/src/Transformers/TSIGKeyUpdateKeyTransformer.php +++ b/src/Transformers/TSIGKeyUpdateKeyTransformer.php @@ -2,11 +2,13 @@ namespace Exonet\Powerdns\Transformers; -class TSIGKeyUpdateKeyTransformer extends Transformer { +class TSIGKeyUpdateKeyTransformer extends Transformer +{ /** * {@inheritdoc} */ - public function transform() { + public function transform() + { return (object) [ 'key' => $this->data->getKey(), ]; diff --git a/src/Transformers/TSIGKeyUpdateNameTransformer.php b/src/Transformers/TSIGKeyUpdateNameTransformer.php index bf38eac..ddae7e9 100644 --- a/src/Transformers/TSIGKeyUpdateNameTransformer.php +++ b/src/Transformers/TSIGKeyUpdateNameTransformer.php @@ -2,11 +2,13 @@ namespace Exonet\Powerdns\Transformers; -class TSIGKeyUpdateNameTransformer extends Transformer { +class TSIGKeyUpdateNameTransformer extends Transformer +{ /** * {@inheritdoc} */ - public function transform() { + public function transform() + { return (object) [ 'name' => $this->data->getName(), ]; diff --git a/src/Transformers/Transformer.php b/src/Transformers/Transformer.php index fc0e146..ba5e7bb 100644 --- a/src/Transformers/Transformer.php +++ b/src/Transformers/Transformer.php @@ -2,7 +2,8 @@ namespace Exonet\Powerdns\Transformers; -abstract class Transformer { +abstract class Transformer +{ /** * @var mixed[] Array holding the data to transform. */ @@ -13,7 +14,8 @@ abstract class Transformer { * * @param null $data (optional) The data to transform. */ - public function __construct($data = null) { + public function __construct($data = null) + { if ($data) { $this->setData($data); } @@ -26,7 +28,8 @@ public function __construct($data = null) { * * @return $this The current transformer instance. */ - public function setData($data): self { + public function setData($data): self + { $this->data = $data; return $this; diff --git a/tests/functional/TSIGKeysTest.php b/tests/functional/TSIGKeysTest.php index 3ca0198..a0e87ea 100644 --- a/tests/functional/TSIGKeysTest.php +++ b/tests/functional/TSIGKeysTest.php @@ -8,16 +8,16 @@ /** * @internal */ -class TSIGKeysTest extends FunctionalTestCase { +class TSIGKeysTest extends FunctionalTestCase +{ /** - * test that normal creation of a default key works, asserting that the key is not empty - * - * @return void + * test that normal creation of a default key works, asserting that the key is not empty. */ - public function testCreateTSIGKey(): void { - $name = 'tsigkey-' . mt_rand(100, 10000); + public function testCreateTSIGKey(): void + { + $name = 'tsigkey-'.mt_rand(100, 10000); - $manager = $this->powerdns->tsigkeys(); + $manager = $this->powerdns->tsigkeys(); $resource = new TSIGKeyResource(); $resource->setName($name); @@ -33,14 +33,13 @@ public function testCreateTSIGKey(): void { } /** - * testing the the single endpoint works - * - * @return void + * testing the the single endpoint works. */ - public function testGetSingle(): void { - $name = 'test-key2-' . mt_rand(100, 10000) . microtime(false); + public function testGetSingle(): void + { + $name = 'test-key2-'.mt_rand(100, 10000).microtime(false); - $manager = $this->powerdns->tsigkeys(); + $manager = $this->powerdns->tsigkeys(); $resource = new TSIGKeyResource(); $resource->setName($name); @@ -61,14 +60,13 @@ public function testGetSingle(): void { } /** - * testing that creating a key with a very weird name works - * - * @return void + * testing that creating a key with a very weird name works. */ - public function testCreateWithNonUrlFriendlyName(): void { - $name = "this/is/not/aa-_412'aur\\asd-url-friendly-" . mt_rand(100, 10000); + public function testCreateWithNonUrlFriendlyName(): void + { + $name = "this/is/not/aa-_412'aur\\asd-url-friendly-".mt_rand(100, 10000); - $manager = $this->powerdns->tsigkeys(); + $manager = $this->powerdns->tsigkeys(); $resource = new TSIGKeyResource(); $resource->setName($name); @@ -83,14 +81,13 @@ public function testCreateWithNonUrlFriendlyName(): void { } /** - * testing that the delete function works - * - * @return void + * testing that the delete function works. */ - public function testDelete(): void { - $name = 'tsigkey-' . mt_rand(100, 10000); + public function testDelete(): void + { + $name = 'tsigkey-'.mt_rand(100, 10000); - $manager = $this->powerdns->tsigkeys(); + $manager = $this->powerdns->tsigkeys(); $resource = new TSIGKeyResource(); $resource->setName($name); @@ -108,13 +105,12 @@ public function testDelete(): void { * testing that changing the algorithm works. * * changing the algo does not regenerate the key. - * - * @return void */ - public function testChangeAlgorithm(): void { - $name = 'tsigkey-' . time(); + public function testChangeAlgorithm(): void + { + $name = 'tsigkey-'.time(); - $manager = $this->powerdns->tsigkeys(); + $manager = $this->powerdns->tsigkeys(); $resource = new TSIGKeyResource(); $resource->setName($name); @@ -124,13 +120,12 @@ public function testChangeAlgorithm(): void { // update $upd = new TSIGKeyResource([ - 'id' => $key->getId(), - 'algorithm' => TSIGKeyAlgorithms::HMAC_SHA256 + 'id' => $key->getId(), + 'algorithm' => TSIGKeyAlgorithms::HMAC_SHA256, ]); $updatedKey = $manager->updateAlgorithm($upd); - $this->assertNotEquals($updatedKey->getAlgorithm(), $key->getAlgorithm()); $this->assertEquals($updatedKey->getKey(), $key->getKey()); @@ -143,14 +138,13 @@ public function testChangeAlgorithm(): void { * * As per the note in the powerdns documentation, updating the * name does create a new key with the same values as the old key, removing the odl one after copy. - * - * @return void */ - public function testChangeName(): void { - $name = 'tsigkey-' . time(); - $nameToUpdate = 'tsigkey2-' . time(); + public function testChangeName(): void + { + $name = 'tsigkey-'.time(); + $nameToUpdate = 'tsigkey2-'.time(); - $manager = $this->powerdns->tsigkeys(); + $manager = $this->powerdns->tsigkeys(); $resource = new TSIGKeyResource(); $resource->setName($name); @@ -160,13 +154,12 @@ public function testChangeName(): void { // update $upd = new TSIGKeyResource([ - 'id' => $key->getId(), - 'name' => $nameToUpdate + 'id' => $key->getId(), + 'name' => $nameToUpdate, ]); $updatedKey = $manager->updateName($upd); - $this->assertEquals($updatedKey->getAlgorithm(), $key->getAlgorithm()); // the key does not change when updating the name $this->assertEquals($updatedKey->getKey(), $key->getKey());