diff --git a/bootstrap/repl.php b/bootstrap/repl.php index 1580949..5207b85 100644 --- a/bootstrap/repl.php +++ b/bootstrap/repl.php @@ -5,28 +5,37 @@ use RemotelyLiving\PHPDNS\Entities\DNSRecord; use RemotelyLiving\PHPDNS\Entities\DNSRecordType; use RemotelyLiving\PHPDNS\Entities\DNSRecordCollection; +use RemotelyLiving\PHPDNS\Factories\SpatieDNS; +use RemotelyLiving\PHPDNS\Mappers\Dig; +use RemotelyLiving\PHPDNS\Observability\Subscribers\STDIOSubscriber; +use RemotelyLiving\PHPDNS\Resolvers\Cached; +use RemotelyLiving\PHPDNS\Resolvers\Chain; +use RemotelyLiving\PHPDNS\Resolvers\CloudFlare; +use RemotelyLiving\PHPDNS\Resolvers\GoogleDNS; +use RemotelyLiving\PHPDNS\Resolvers\LocalSystem; +use Symfony\Component\Cache\Adapter\FilesystemAdapter; class_alias(Hostname::class, 'Hostname'); class_alias(DNSRecord::class, 'DNSRecord'); class_alias(DNSRecordType::class, 'DNSRecordType'); class_alias(DNSRecordCollection::class, 'DNSRecordCollection'); -$stdOut = new \SplFileObject('php://stdout'); -$stdErr = new \SplFileObject('php://stderr'); -$IOSubscriber = new \RemotelyLiving\PHPDNS\Observability\Subscribers\STDIOSubscriber($stdOut, $stdErr); +$stdOut = new SplFileObject('php://stdout'); +$stdErr = new SplFileObject('php://stderr'); +$IOSubscriber = new STDIOSubscriber($stdOut, $stdErr); -$localSystemResolver = new \RemotelyLiving\PHPDNS\Resolvers\LocalSystem(); +$localSystemResolver = new LocalSystem(); $localSystemResolver->addSubscriber($IOSubscriber); -$googleDNSResolver = new \RemotelyLiving\PHPDNS\Resolvers\GoogleDNS(); +$googleDNSResolver = new GoogleDNS(); $googleDNSResolver->addSubscriber($IOSubscriber); -$cloudFlareResolver = new \RemotelyLiving\PHPDNS\Resolvers\CloudFlare(); +$cloudFlareResolver = new CloudFlare(); $cloudFlareResolver->addSubscriber($IOSubscriber); -$digResolver = new \RemotelyLiving\PHPDNS\Resolvers\Dig(new \RemotelyLiving\PHPDNS\Factories\SpatieDNS(), new \RemotelyLiving\PHPDNS\Mappers\Dig()); +$digResolver = new \RemotelyLiving\PHPDNS\Resolvers\Dig(new SpatieDNS(), new Dig()); $digResolver->addSubscriber($IOSubscriber); -$chainResolver = new \RemotelyLiving\PHPDNS\Resolvers\Chain($cloudFlareResolver, $googleDNSResolver, $localSystemResolver); -$cachedResolver = new \RemotelyLiving\PHPDNS\Resolvers\Cached(new \Symfony\Component\Cache\Adapter\FilesystemAdapter(), $chainResolver); +$chainResolver = new Chain($cloudFlareResolver, $googleDNSResolver, $localSystemResolver); +$cachedResolver = new Cached(new FilesystemAdapter(), $chainResolver); $cachedResolver->addSubscriber($IOSubscriber); \ No newline at end of file diff --git a/composer.json b/composer.json index 2cbd31f..7d0c531 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ "ext-filter": "*", "ext-intl": "*", "ext-mbstring": "*", - "guzzlehttp/guzzle": "^6.0", + "guzzlehttp/guzzle": "^7.0 || ^6.0", "psr/cache": "^1.0", "symfony/event-dispatcher": "^5.0 || ^4.0 || ^3.0", "psr/log": "^1.0", diff --git a/composer.lock b/composer.lock index 1e912b6..8285bfc 100644 --- a/composer.lock +++ b/composer.lock @@ -4,41 +4,47 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "d26c64d4692ea278aef1da427d67a95a", + "content-hash": "8ea7568062733eea52aba2ecefc0fa21", "packages": [ { "name": "guzzlehttp/guzzle", - "version": "6.5.5", + "version": "7.2.0", "source": { "type": "git", "url": "https://github.com/guzzle/guzzle.git", - "reference": "9d4290de1cfd701f38099ef7e183b64b4b7b0c5e" + "reference": "0aa74dfb41ae110835923ef10a9d803a22d50e79" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/guzzle/zipball/9d4290de1cfd701f38099ef7e183b64b4b7b0c5e", - "reference": "9d4290de1cfd701f38099ef7e183b64b4b7b0c5e", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/0aa74dfb41ae110835923ef10a9d803a22d50e79", + "reference": "0aa74dfb41ae110835923ef10a9d803a22d50e79", "shasum": "" }, "require": { "ext-json": "*", - "guzzlehttp/promises": "^1.0", - "guzzlehttp/psr7": "^1.6.1", - "php": ">=5.5", - "symfony/polyfill-intl-idn": "^1.17.0" + "guzzlehttp/promises": "^1.4", + "guzzlehttp/psr7": "^1.7", + "php": "^7.2.5 || ^8.0", + "psr/http-client": "^1.0" + }, + "provide": { + "psr/http-client-implementation": "1.0" }, "require-dev": { "ext-curl": "*", - "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.4 || ^7.0", + "php-http/client-integration-tests": "^3.0", + "phpunit/phpunit": "^8.5.5 || ^9.3.5", "psr/log": "^1.1" }, "suggest": { + "ext-curl": "Required for CURL handler support", + "ext-intl": "Required for Internationalized Domain Name (IDN) support", "psr/log": "Required for using the Log middleware" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "6.5-dev" + "dev-master": "7.1-dev" } }, "autoload": { @@ -58,6 +64,11 @@ "name": "Michael Dowling", "email": "mtdowling@gmail.com", "homepage": "https://github.com/mtdowling" + }, + { + "name": "Márk Sági-Kazár", + "email": "mark.sagikazar@gmail.com", + "homepage": "https://sagikazarmark.hu" } ], "description": "Guzzle is a PHP HTTP client library", @@ -68,10 +79,30 @@ "framework", "http", "http client", + "psr-18", + "psr-7", "rest", "web service" ], - "time": "2020-06-16T21:01:06+00:00" + "funding": [ + { + "url": "https://github.com/GrahamCampbell", + "type": "github" + }, + { + "url": "https://github.com/Nyholm", + "type": "github" + }, + { + "url": "https://github.com/alexeyshockov", + "type": "github" + }, + { + "url": "https://github.com/gmponos", + "type": "github" + } + ], + "time": "2020-10-10T11:47:56+00:00" }, { "name": "guzzlehttp/promises", @@ -196,66 +227,68 @@ "time": "2020-09-30T07:37:11+00:00" }, { - "name": "paragonie/random_compat", - "version": "v9.99.100", + "name": "psr/cache", + "version": "1.0.1", "source": { "type": "git", - "url": "https://github.com/paragonie/random_compat.git", - "reference": "996434e5492cb4c3edcb9168db6fbb1359ef965a" + "url": "https://github.com/php-fig/cache.git", + "reference": "d11b50ad223250cf17b86e38383413f5a6764bf8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/paragonie/random_compat/zipball/996434e5492cb4c3edcb9168db6fbb1359ef965a", - "reference": "996434e5492cb4c3edcb9168db6fbb1359ef965a", + "url": "https://api.github.com/repos/php-fig/cache/zipball/d11b50ad223250cf17b86e38383413f5a6764bf8", + "reference": "d11b50ad223250cf17b86e38383413f5a6764bf8", "shasum": "" }, "require": { - "php": ">= 7" + "php": ">=5.3.0" }, - "require-dev": { - "phpunit/phpunit": "4.*|5.*", - "vimeo/psalm": "^1" + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } }, - "suggest": { - "ext-libsodium": "Provides a modern crypto API that can be used to generate random bytes." + "autoload": { + "psr-4": { + "Psr\\Cache\\": "src/" + } }, - "type": "library", "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], "authors": [ { - "name": "Paragon Initiative Enterprises", - "email": "security@paragonie.com", - "homepage": "https://paragonie.com" + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" } ], - "description": "PHP 5.x polyfill for random_bytes() and random_int() from PHP 7", + "description": "Common interface for caching libraries", "keywords": [ - "csprng", - "polyfill", - "pseudorandom", - "random" + "cache", + "psr", + "psr-6" ], - "time": "2020-10-15T08:29:30+00:00" + "time": "2016-08-06T20:24:11+00:00" }, { - "name": "psr/cache", + "name": "psr/http-client", "version": "1.0.1", "source": { "type": "git", - "url": "https://github.com/php-fig/cache.git", - "reference": "d11b50ad223250cf17b86e38383413f5a6764bf8" + "url": "https://github.com/php-fig/http-client.git", + "reference": "2dfb5f6c5eff0e91e20e913f8c5452ed95b86621" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/cache/zipball/d11b50ad223250cf17b86e38383413f5a6764bf8", - "reference": "d11b50ad223250cf17b86e38383413f5a6764bf8", + "url": "https://api.github.com/repos/php-fig/http-client/zipball/2dfb5f6c5eff0e91e20e913f8c5452ed95b86621", + "reference": "2dfb5f6c5eff0e91e20e913f8c5452ed95b86621", "shasum": "" }, "require": { - "php": ">=5.3.0" + "php": "^7.0 || ^8.0", + "psr/http-message": "^1.0" }, "type": "library", "extra": { @@ -265,7 +298,7 @@ }, "autoload": { "psr-4": { - "Psr\\Cache\\": "src/" + "Psr\\Http\\Client\\": "src/" } }, "notification-url": "https://packagist.org/downloads/", @@ -278,13 +311,15 @@ "homepage": "http://www.php-fig.org/" } ], - "description": "Common interface for caching libraries", + "description": "Common interface for HTTP clients", + "homepage": "https://github.com/php-fig/http-client", "keywords": [ - "cache", + "http", + "http-client", "psr", - "psr-6" + "psr-18" ], - "time": "2016-08-06T20:24:11+00:00" + "time": "2020-06-29T06:28:15+00:00" }, { "name": "psr/http-message", @@ -637,322 +672,6 @@ ], "time": "2020-07-06T13:19:58+00:00" }, - { - "name": "symfony/polyfill-intl-idn", - "version": "v1.18.1", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-intl-idn.git", - "reference": "5dcab1bc7146cf8c1beaa4502a3d9be344334251" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-intl-idn/zipball/5dcab1bc7146cf8c1beaa4502a3d9be344334251", - "reference": "5dcab1bc7146cf8c1beaa4502a3d9be344334251", - "shasum": "" - }, - "require": { - "php": ">=5.3.3", - "symfony/polyfill-intl-normalizer": "^1.10", - "symfony/polyfill-php70": "^1.10", - "symfony/polyfill-php72": "^1.10" - }, - "suggest": { - "ext-intl": "For best performance" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.18-dev" - }, - "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Polyfill\\Intl\\Idn\\": "" - }, - "files": [ - "bootstrap.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Laurent Bassin", - "email": "laurent@bassin.info" - }, - { - "name": "Trevor Rowbotham", - "email": "trevor.rowbotham@pm.me" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 functions", - "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "idn", - "intl", - "polyfill", - "portable", - "shim" - ], - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2020-08-04T06:02:08+00:00" - }, - { - "name": "symfony/polyfill-intl-normalizer", - "version": "v1.18.1", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-intl-normalizer.git", - "reference": "37078a8dd4a2a1e9ab0231af7c6cb671b2ed5a7e" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-intl-normalizer/zipball/37078a8dd4a2a1e9ab0231af7c6cb671b2ed5a7e", - "reference": "37078a8dd4a2a1e9ab0231af7c6cb671b2ed5a7e", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "suggest": { - "ext-intl": "For best performance" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.18-dev" - }, - "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Polyfill\\Intl\\Normalizer\\": "" - }, - "files": [ - "bootstrap.php" - ], - "classmap": [ - "Resources/stubs" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony polyfill for intl's Normalizer class and related functions", - "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "intl", - "normalizer", - "polyfill", - "portable", - "shim" - ], - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2020-07-14T12:35:20+00:00" - }, - { - "name": "symfony/polyfill-php70", - "version": "v1.18.1", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-php70.git", - "reference": "0dd93f2c578bdc9c72697eaa5f1dd25644e618d3" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php70/zipball/0dd93f2c578bdc9c72697eaa5f1dd25644e618d3", - "reference": "0dd93f2c578bdc9c72697eaa5f1dd25644e618d3", - "shasum": "" - }, - "require": { - "paragonie/random_compat": "~1.0|~2.0|~9.99", - "php": ">=5.3.3" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.18-dev" - }, - "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Polyfill\\Php70\\": "" - }, - "files": [ - "bootstrap.php" - ], - "classmap": [ - "Resources/stubs" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony polyfill backporting some PHP 7.0+ features to lower PHP versions", - "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "polyfill", - "portable", - "shim" - ], - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2020-07-14T12:35:20+00:00" - }, - { - "name": "symfony/polyfill-php72", - "version": "v1.18.1", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-php72.git", - "reference": "639447d008615574653fb3bc60d1986d7172eaae" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php72/zipball/639447d008615574653fb3bc60d1986d7172eaae", - "reference": "639447d008615574653fb3bc60d1986d7172eaae", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.18-dev" - }, - "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Polyfill\\Php72\\": "" - }, - "files": [ - "bootstrap.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions", - "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "polyfill", - "portable", - "shim" - ], - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2020-07-14T12:35:20+00:00" - }, { "name": "symfony/polyfill-php80", "version": "v1.18.1", diff --git a/src/Entities/CAAData.php b/src/Entities/CAAData.php index ada77f9..6f95f32 100644 --- a/src/Entities/CAAData.php +++ b/src/Entities/CAAData.php @@ -4,6 +4,12 @@ use RemotelyLiving\PHPDNS\Exceptions; +use function preg_match; +use function serialize; +use function str_ireplace; +use function trim; +use function unserialize; + final class CAAData extends DataAbstract { private int $flags; @@ -52,7 +58,7 @@ public function toArray(): array public function serialize(): string { - return \serialize($this->toArray()); + return serialize($this->toArray()); } /** @@ -60,7 +66,7 @@ public function serialize(): string */ public function unserialize($serialized): void { - $unserialized = \unserialize($serialized); + $unserialized = unserialize($serialized); $this->flags = $unserialized['flags']; $this->tag = $unserialized['tag']; $this->value = $unserialized['value']; @@ -68,9 +74,9 @@ public function unserialize($serialized): void private function normalizeValue(string $value): string { - $normalized = \trim(\str_ireplace('"', '', $value)); + $normalized = trim(str_ireplace('"', '', $value)); - if (\preg_match('/\s/m', $normalized)) { + if (preg_match('/\s/m', $normalized)) { throw new Exceptions\InvalidArgumentException("$value is not a valid CAA value"); } diff --git a/src/Entities/CNAMEData.php b/src/Entities/CNAMEData.php index dbf067f..ac978ae 100644 --- a/src/Entities/CNAMEData.php +++ b/src/Entities/CNAMEData.php @@ -2,9 +2,12 @@ namespace RemotelyLiving\PHPDNS\Entities; +use function serialize; +use function unserialize; + final class CNAMEData extends DataAbstract { - private \RemotelyLiving\PHPDNS\Entities\Hostname $hostname; + private Hostname $hostname; public function __construct(Hostname $hostname) { @@ -30,7 +33,7 @@ public function toArray(): array public function serialize(): string { - return \serialize($this->toArray()); + return serialize($this->toArray()); } /** @@ -38,7 +41,7 @@ public function serialize(): string */ public function unserialize($serialized): void { - $unserialized = \unserialize($serialized); + $unserialized = unserialize($serialized); $this->hostname = new Hostname($unserialized['hostname']); } } diff --git a/src/Entities/DNSRecord.php b/src/Entities/DNSRecord.php index 46c940a..9b742b8 100644 --- a/src/Entities/DNSRecord.php +++ b/src/Entities/DNSRecord.php @@ -4,19 +4,22 @@ use RemotelyLiving\PHPDNS\Entities\Interfaces\DNSRecordInterface; +use function serialize; +use function unserialize; + final class DNSRecord extends EntityAbstract implements DNSRecordInterface { - private \RemotelyLiving\PHPDNS\Entities\DNSRecordType $recordType; + private DNSRecordType $recordType; - private \RemotelyLiving\PHPDNS\Entities\Hostname $hostname; + private Hostname $hostname; private int $TTL; - private ?\RemotelyLiving\PHPDNS\Entities\IPAddress $IPAddress; + private ?IPAddress $IPAddress; private string $class; - private ?\RemotelyLiving\PHPDNS\Entities\DataAbstract $data; + private ?DataAbstract $data; /** * @var string */ @@ -128,7 +131,7 @@ public function equals(DNSRecordInterface $record): bool public function serialize(): string { - return \serialize($this->toArray()); + return serialize($this->toArray()); } /** @@ -136,7 +139,7 @@ public function serialize(): string */ public function unserialize($serialized): void { - $unserialized = \unserialize($serialized); + $unserialized = unserialize($serialized); $rawIPAddres = $unserialized['IPAddress'] ?? null; $this->recordType = DNSRecordType::createFromString($unserialized['type']); diff --git a/src/Entities/DNSRecordCollection.php b/src/Entities/DNSRecordCollection.php index 6622545..1b85ff8 100644 --- a/src/Entities/DNSRecordCollection.php +++ b/src/Entities/DNSRecordCollection.php @@ -2,23 +2,32 @@ namespace RemotelyLiving\PHPDNS\Entities; +use ArrayAccess; +use ArrayIterator; +use Countable; +use Iterator; use RemotelyLiving\PHPDNS\Entities\Interfaces\Arrayable; use RemotelyLiving\PHPDNS\Entities\Interfaces\DNSRecordInterface; use RemotelyLiving\PHPDNS\Entities\Interfaces\Serializable; use RemotelyLiving\PHPDNS\Exceptions\InvalidArgumentException; +use function array_filter; +use function array_shift; +use function serialize; +use function unserialize; + final class DNSRecordCollection extends EntityAbstract implements - \ArrayAccess, - \Iterator, - \Countable, + ArrayAccess, + Iterator, + Countable, Arrayable, Serializable { - private \ArrayIterator $records; + private ArrayIterator $records; public function __construct(DNSRecordInterface ...$records) { - $this->records = new \ArrayIterator($records); + $this->records = new ArrayIterator($records); } public function toArray(): array @@ -30,13 +39,13 @@ public function pickFirst(): ?DNSRecordInterface { $copy = $this->records->getArrayCopy(); - return \array_shift($copy); + return array_shift($copy); } public function filteredByType(DNSRecordType $type): self { return new self( - ...\array_filter($this->records->getArrayCopy(), fn(DNSRecord $record) => $record->getType()->equals($type)) + ...array_filter($this->records->getArrayCopy(), fn(DNSRecord $record) => $record->getType()->equals($type)) ); } @@ -118,7 +127,7 @@ public function isEmpty(): bool public function serialize(): string { - return \serialize($this->records->getArrayCopy()); + return serialize($this->records->getArrayCopy()); } /** @@ -126,7 +135,7 @@ public function serialize(): string */ public function unserialize($serialized): void { - $this->records = new \ArrayIterator(\unserialize($serialized)); + $this->records = new ArrayIterator(unserialize($serialized)); } public function jsonSerialize(): array @@ -158,7 +167,7 @@ private function filterValues(callable $eval): self $records = $this->records->getArrayCopy(); /** @var \RemotelyLiving\PHPDNS\Entities\Interfaces\DNSRecordInterface $record */ - while ($record = \array_shift($records)) { + while ($record = array_shift($records)) { if ($eval($record, new self(...$records))) { $filtered[] = $record; } diff --git a/src/Entities/DNSRecordType.php b/src/Entities/DNSRecordType.php index cd70007..d1367aa 100644 --- a/src/Entities/DNSRecordType.php +++ b/src/Entities/DNSRecordType.php @@ -4,6 +4,10 @@ use RemotelyLiving\PHPDNS\Exceptions\InvalidArgumentException; +use function array_flip; +use function in_array; +use function strtoupper; + final class DNSRecordType extends EntityAbstract { public const TYPE_A = 'A'; @@ -62,7 +66,7 @@ final class DNSRecordType extends EntityAbstract */ public function __construct(string $type) { - if (!\in_array($type, self::VALID_TYPES, true)) { + if (!in_array($type, self::VALID_TYPES, true)) { throw new InvalidArgumentException("{$type} is not an existing DNS record type"); } @@ -93,12 +97,12 @@ public static function createFromString(string $type): DNSRecordType public function toInt(): int { - return (int) \array_flip(self::CODE_TYPE_MAP)[$this->type]; + return (int) array_flip(self::CODE_TYPE_MAP)[$this->type]; } public function isA(string $type): bool { - return $this->type === \strtoupper($type); + return $this->type === strtoupper($type); } public function equals(DNSRecordType $recordType): bool diff --git a/src/Entities/DataAbstract.php b/src/Entities/DataAbstract.php index 0607a9e..98dc365 100644 --- a/src/Entities/DataAbstract.php +++ b/src/Entities/DataAbstract.php @@ -6,6 +6,10 @@ use RemotelyLiving\PHPDNS\Entities\Interfaces\Serializable; use RemotelyLiving\PHPDNS\Exceptions\InvalidArgumentException; +use function count; +use function explode; +use function trim; + abstract class DataAbstract implements Arrayable, Serializable { abstract public function __toString(): string; @@ -23,7 +27,7 @@ public function equals(DataAbstract $dataAbstract): bool public static function createFromTypeAndString(DNSRecordType $recordType, string $data): self { if ($recordType->isA(DNSRecordType::TYPE_TXT)) { - return new TXTData(\trim($data, '"')); + return new TXTData(trim($data, '"')); } if ($recordType->isA(DNSRecordType::TYPE_NS)) { @@ -52,7 +56,7 @@ public static function createFromTypeAndString(DNSRecordType $recordType, string ); } - if ($recordType->isA(DNSRecordType::TYPE_CAA) && \count($parsed) === 3) { + if ($recordType->isA(DNSRecordType::TYPE_CAA) && count($parsed) === 3) { return new CAAData((int)$parsed[0], (string)$parsed[1], $parsed[2]); } @@ -75,6 +79,6 @@ public function jsonSerialize(): array private static function parseDataToArray(string $data): array { - return \explode(' ', $data); + return explode(' ', $data); } } diff --git a/src/Entities/Hostname.php b/src/Entities/Hostname.php index 8b44a04..6e49c3f 100644 --- a/src/Entities/Hostname.php +++ b/src/Entities/Hostname.php @@ -4,6 +4,13 @@ use RemotelyLiving\PHPDNS\Exceptions\InvalidArgumentException; +use function filter_var; +use function idn_to_ascii; +use function idn_to_utf8; +use function mb_strtolower; +use function substr; +use function trim; + final class Hostname extends EntityAbstract { private string $hostname; @@ -15,7 +22,7 @@ public function __construct(string $hostname) { $hostname = $this->normalizeHostName($hostname); - if (\filter_var($hostname, FILTER_VALIDATE_DOMAIN) !== $hostname) { + if (filter_var($hostname, FILTER_VALIDATE_DOMAIN) !== $hostname) { throw new InvalidArgumentException("{$hostname} is not a valid hostname"); } @@ -44,7 +51,7 @@ public function getHostName(): string public function getHostnameWithoutTrailingDot(): string { - return \substr($this->hostname, 0, -1); + return substr($this->hostname, 0, -1); } public function isPunycoded(): bool @@ -54,19 +61,19 @@ public function isPunycoded(): bool public function toUTF8(): string { - return (string)\idn_to_utf8($this->hostname, IDNA_ERROR_PUNYCODE, INTL_IDNA_VARIANT_UTS46); + return (string)idn_to_utf8($this->hostname, IDNA_ERROR_PUNYCODE, INTL_IDNA_VARIANT_UTS46); } private static function punyCode(string $hostname): string { - return (string)\idn_to_ascii($hostname, IDNA_ERROR_PUNYCODE, INTL_IDNA_VARIANT_UTS46); + return (string)idn_to_ascii($hostname, IDNA_ERROR_PUNYCODE, INTL_IDNA_VARIANT_UTS46); } private function normalizeHostName(string $hostname): string { - $hostname = self::punyCode(\mb_strtolower(\trim($hostname))); + $hostname = self::punyCode(mb_strtolower(trim($hostname))); - if (\substr($hostname, -1) !== '.') { + if (substr($hostname, -1) !== '.') { return "{$hostname}."; } diff --git a/src/Entities/IPAddress.php b/src/Entities/IPAddress.php index 2c6a9ab..e3a6471 100644 --- a/src/Entities/IPAddress.php +++ b/src/Entities/IPAddress.php @@ -4,6 +4,9 @@ use RemotelyLiving\PHPDNS\Exceptions\InvalidArgumentException; +use function filter_var; +use function trim; + final class IPAddress extends EntityAbstract { private string $IPAddress; @@ -13,7 +16,7 @@ final class IPAddress extends EntityAbstract */ public function __construct(string $IPAddress) { - $IPAddress = \trim($IPAddress); + $IPAddress = trim($IPAddress); if (self::isValid($IPAddress) === false) { throw new InvalidArgumentException("{$IPAddress} is not a valid IP address"); @@ -29,7 +32,7 @@ public function __toString(): string public static function isValid(string $IPAddress): bool { - return (bool) \filter_var($IPAddress, FILTER_VALIDATE_IP); + return (bool) filter_var($IPAddress, FILTER_VALIDATE_IP); } public static function createFromString(string $IPAddress): IPAddress @@ -49,11 +52,11 @@ public function getIPAddress(): string public function isIPv6(): bool { - return (bool) \filter_var($this->IPAddress, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6); + return (bool) filter_var($this->IPAddress, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6); } public function isIPv4(): bool { - return (bool) \filter_var($this->IPAddress, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4); + return (bool) filter_var($this->IPAddress, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4); } } diff --git a/src/Entities/Interfaces/Serializable.php b/src/Entities/Interfaces/Serializable.php index dfdfd69..2a16232 100644 --- a/src/Entities/Interfaces/Serializable.php +++ b/src/Entities/Interfaces/Serializable.php @@ -2,7 +2,9 @@ namespace RemotelyLiving\PHPDNS\Entities\Interfaces; -interface Serializable extends \Serializable, \JsonSerializable +use JsonSerializable; + +interface Serializable extends \Serializable, JsonSerializable { public function serialize(): string; diff --git a/src/Entities/MXData.php b/src/Entities/MXData.php index 9fd3e8f..7928a55 100644 --- a/src/Entities/MXData.php +++ b/src/Entities/MXData.php @@ -2,9 +2,12 @@ namespace RemotelyLiving\PHPDNS\Entities; +use function serialize; +use function unserialize; + final class MXData extends DataAbstract { - private \RemotelyLiving\PHPDNS\Entities\Hostname $target; + private Hostname $target; private int $priority; @@ -39,7 +42,7 @@ public function toArray(): array public function serialize(): string { - return \serialize($this->toArray()); + return serialize($this->toArray()); } /** @@ -47,7 +50,7 @@ public function serialize(): string */ public function unserialize($serialized): void { - $unserialized = \unserialize($serialized); + $unserialized = unserialize($serialized); $this->target = new Hostname($unserialized['target']); $this->priority = $unserialized['priority']; } diff --git a/src/Entities/NSData.php b/src/Entities/NSData.php index f3d29ec..5d0a8d7 100644 --- a/src/Entities/NSData.php +++ b/src/Entities/NSData.php @@ -2,9 +2,12 @@ namespace RemotelyLiving\PHPDNS\Entities; +use function serialize; +use function unserialize; + final class NSData extends DataAbstract { - private \RemotelyLiving\PHPDNS\Entities\Hostname $target; + private Hostname $target; public function __construct(Hostname $target) { @@ -30,7 +33,7 @@ public function toArray(): array public function serialize(): string { - return \serialize($this->toArray()); + return serialize($this->toArray()); } /** @@ -38,7 +41,7 @@ public function serialize(): string */ public function unserialize($serialized): void { - $unserialized = \unserialize($serialized); + $unserialized = unserialize($serialized); $this->target = new Hostname($unserialized['target']); } } diff --git a/src/Entities/SOAData.php b/src/Entities/SOAData.php index c2b7228..cf7cf4b 100644 --- a/src/Entities/SOAData.php +++ b/src/Entities/SOAData.php @@ -2,11 +2,15 @@ namespace RemotelyLiving\PHPDNS\Entities; +use function serialize; +use function unserialize; +use function vsprintf; + final class SOAData extends DataAbstract { - private \RemotelyLiving\PHPDNS\Entities\Hostname $mname; + private Hostname $mname; - private \RemotelyLiving\PHPDNS\Entities\Hostname $rname; + private Hostname $rname; private int $serial; @@ -42,7 +46,7 @@ public function __construct( public function __toString(): string { - return \vsprintf(self::TEMPLATE, $this->toArray()); + return vsprintf(self::TEMPLATE, $this->toArray()); } /** @@ -117,7 +121,7 @@ public function toArray(): array public function serialize(): string { - return \serialize($this->toArray()); + return serialize($this->toArray()); } /** @@ -125,7 +129,7 @@ public function serialize(): string */ public function unserialize($serialized): void { - $unserialized = \unserialize($serialized); + $unserialized = unserialize($serialized); $this->mname = new Hostname($unserialized['mname']); $this->rname = new Hostname($unserialized['rname']); $this->serial = $unserialized['serial']; diff --git a/src/Entities/SRVData.php b/src/Entities/SRVData.php index 44ba7a0..207babf 100644 --- a/src/Entities/SRVData.php +++ b/src/Entities/SRVData.php @@ -2,6 +2,9 @@ namespace RemotelyLiving\PHPDNS\Entities; +use function serialize; +use function unserialize; + final class SRVData extends DataAbstract { private int $priority; @@ -10,7 +13,7 @@ final class SRVData extends DataAbstract private int $port; - private \RemotelyLiving\PHPDNS\Entities\Hostname $target; + private Hostname $target; public function __construct(int $priority, int $weight, int $port, Hostname $target) { @@ -57,7 +60,7 @@ public function toArray(): array public function serialize(): string { - return \serialize($this->toArray()); + return serialize($this->toArray()); } /** @@ -65,7 +68,7 @@ public function serialize(): string */ public function unserialize($serialized): void { - $unserialized = \unserialize($serialized); + $unserialized = unserialize($serialized); $this->priority = $unserialized['priority']; $this->weight = $unserialized['weight']; $this->port = $unserialized['port']; diff --git a/src/Entities/TXTData.php b/src/Entities/TXTData.php index fed92d0..1a2f1cd 100644 --- a/src/Entities/TXTData.php +++ b/src/Entities/TXTData.php @@ -2,6 +2,9 @@ namespace RemotelyLiving\PHPDNS\Entities; +use function serialize; +use function unserialize; + final class TXTData extends DataAbstract { private string $value; @@ -30,7 +33,7 @@ public function toArray(): array public function serialize(): string { - return \serialize($this->toArray()); + return serialize($this->toArray()); } /** @@ -38,7 +41,7 @@ public function serialize(): string */ public function unserialize($serialized): void { - $unserialized = \unserialize($serialized); + $unserialized = unserialize($serialized); $this->value = $unserialized['value']; } } diff --git a/src/Exceptions/Exception.php b/src/Exceptions/Exception.php index 456c80d..31ec55f 100644 --- a/src/Exceptions/Exception.php +++ b/src/Exceptions/Exception.php @@ -2,7 +2,9 @@ namespace RemotelyLiving\PHPDNS\Exceptions; -class Exception extends \Exception implements \JsonSerializable +use JsonSerializable; + +class Exception extends \Exception implements JsonSerializable { public function jsonSerialize(): array { diff --git a/src/Mappers/CloudFlare.php b/src/Mappers/CloudFlare.php index c061d5a..81aa364 100644 --- a/src/Mappers/CloudFlare.php +++ b/src/Mappers/CloudFlare.php @@ -6,6 +6,8 @@ use RemotelyLiving\PHPDNS\Entities\DNSRecordType; use RemotelyLiving\PHPDNS\Entities\IPAddress; +use function str_ireplace; + final class CloudFlare extends MapperAbstract { /** @@ -20,7 +22,7 @@ public function toDNSRecord(): DNSRecord : null; $value = (isset($this->fields[self::DATA]) && !$IPAddress) - ? \str_ireplace('"', '', (string)$this->fields[self::DATA]) + ? str_ireplace('"', '', (string)$this->fields[self::DATA]) : null; return DNSRecord::createFromPrimitives( diff --git a/src/Mappers/GoogleDNS.php b/src/Mappers/GoogleDNS.php index 7143419..64c4e1d 100644 --- a/src/Mappers/GoogleDNS.php +++ b/src/Mappers/GoogleDNS.php @@ -7,6 +7,8 @@ use RemotelyLiving\PHPDNS\Entities\Hostname; use RemotelyLiving\PHPDNS\Entities\IPAddress; +use function str_ireplace; + final class GoogleDNS extends MapperAbstract { /** @@ -21,7 +23,7 @@ public function toDNSRecord(): DNSRecord : null; $value = (isset($this->fields[self::DATA]) && !$IPAddress) - ? \str_ireplace('"', '', (string)$this->fields[self::DATA]) + ? str_ireplace('"', '', (string)$this->fields[self::DATA]) : null; return DNSRecord::createFromPrimitives( diff --git a/src/Mappers/LocalSystem.php b/src/Mappers/LocalSystem.php index 1531d34..b643717 100644 --- a/src/Mappers/LocalSystem.php +++ b/src/Mappers/LocalSystem.php @@ -6,23 +6,41 @@ use RemotelyLiving\PHPDNS\Entities\DNSRecordType; use RemotelyLiving\PHPDNS\Entities\Interfaces\DNSRecordInterface; +use function array_flip; +use function sprintf; + +use const DNS_A; +use const DNS_A6; +use const DNS_AAAA; +use const DNS_ANY; +use const DNS_CAA; +use const DNS_CNAME; +use const DNS_HINFO; +use const DNS_MX; +use const DNS_NAPTR; +use const DNS_NS; +use const DNS_PTR; +use const DNS_SOA; +use const DNS_SRV; +use const DNS_TXT; + final class LocalSystem extends MapperAbstract { private const PHP_CODE_TYPE_MAP = [ - \DNS_A => DNSRecordType::TYPE_A, - \DNS_CNAME => DNSRecordType::TYPE_CNAME, - \DNS_HINFO => DNSRecordType::TYPE_HINFO, - \DNS_CAA => DNSRecordType::TYPE_CAA, - \DNS_MX => DNSRecordType::TYPE_MX, - \DNS_NS => DNSRecordType::TYPE_NS, - \DNS_PTR => DNSRecordType::TYPE_PTR, - \DNS_SOA => DNSRecordType::TYPE_SOA, - \DNS_TXT => DNSRecordType::TYPE_TXT, - \DNS_AAAA => DNSRecordType::TYPE_AAAA, - \DNS_SRV => DNSRecordType::TYPE_SRV, - \DNS_NAPTR => DNSRecordType::TYPE_NAPTR, - \DNS_A6 => DNSRecordType::TYPE_A6, - \DNS_ANY => DNSRecordType::TYPE_ANY, + DNS_A => DNSRecordType::TYPE_A, + DNS_CNAME => DNSRecordType::TYPE_CNAME, + DNS_HINFO => DNSRecordType::TYPE_HINFO, + DNS_CAA => DNSRecordType::TYPE_CAA, + DNS_MX => DNSRecordType::TYPE_MX, + DNS_NS => DNSRecordType::TYPE_NS, + DNS_PTR => DNSRecordType::TYPE_PTR, + DNS_SOA => DNSRecordType::TYPE_SOA, + DNS_TXT => DNSRecordType::TYPE_TXT, + DNS_AAAA => DNSRecordType::TYPE_AAAA, + DNS_SRV => DNSRecordType::TYPE_SRV, + DNS_NAPTR => DNSRecordType::TYPE_NAPTR, + DNS_A6 => DNSRecordType::TYPE_A6, + DNS_ANY => DNSRecordType::TYPE_ANY, ]; /** * @var string @@ -61,7 +79,7 @@ public function toDNSRecord(): DNSRecordInterface public function getTypeCodeFromType(DNSRecordType $type): int { - return \array_flip(self::PHP_CODE_TYPE_MAP)[(string)$type] ?? \DNS_ANY; + return array_flip(self::PHP_CODE_TYPE_MAP)[(string)$type] ?? DNS_ANY; } private function formatData(array $fields): ?string @@ -71,7 +89,7 @@ private function formatData(array $fields): ?string } if (isset($fields['mname'])) { - return \sprintf( + return sprintf( self::TEMPLATE, $fields['mname'], $fields['rname'], diff --git a/src/Observability/Events/DNSQueried.php b/src/Observability/Events/DNSQueried.php index 6c18cb3..71c19a7 100644 --- a/src/Observability/Events/DNSQueried.php +++ b/src/Observability/Events/DNSQueried.php @@ -11,13 +11,13 @@ final class DNSQueried extends ObservableEventAbstract { public const NAME = 'dns.queried'; - private \RemotelyLiving\PHPDNS\Resolvers\Interfaces\Resolver $resolver; + private Resolver $resolver; - private \RemotelyLiving\PHPDNS\Entities\Hostname $hostname; + private Hostname $hostname; - private \RemotelyLiving\PHPDNS\Entities\DNSRecordType $recordType; + private DNSRecordType $recordType; - private \RemotelyLiving\PHPDNS\Entities\DNSRecordCollection $recordCollection; + private DNSRecordCollection $recordCollection; public function __construct( Resolver $resolver, diff --git a/src/Observability/Events/DNSQueryFailed.php b/src/Observability/Events/DNSQueryFailed.php index b5ee6bd..d911884 100644 --- a/src/Observability/Events/DNSQueryFailed.php +++ b/src/Observability/Events/DNSQueryFailed.php @@ -11,13 +11,13 @@ final class DNSQueryFailed extends ObservableEventAbstract { public const NAME = 'dns.query.failed'; - private \RemotelyLiving\PHPDNS\Resolvers\Interfaces\Resolver $resolver; + private Resolver $resolver; - private \RemotelyLiving\PHPDNS\Entities\Hostname $hostname; + private Hostname $hostname; - private \RemotelyLiving\PHPDNS\Entities\DNSRecordType $recordType; + private DNSRecordType $recordType; - private \RemotelyLiving\PHPDNS\Exceptions\Exception $error; + private Exception $error; public function __construct(Resolver $resolver, Hostname $hostname, DNSRecordType $recordType, Exception $error) { diff --git a/src/Observability/Events/ObservableEventAbstract.php b/src/Observability/Events/ObservableEventAbstract.php index e17fbcd..bd196d3 100644 --- a/src/Observability/Events/ObservableEventAbstract.php +++ b/src/Observability/Events/ObservableEventAbstract.php @@ -2,11 +2,12 @@ namespace RemotelyLiving\PHPDNS\Observability\Events; +use JsonSerializable; use RemotelyLiving\PHPDNS\Entities\Interfaces\Arrayable; use Symfony\Component\EventDispatcher\GenericEvent; abstract class ObservableEventAbstract extends GenericEvent implements - \JsonSerializable, + JsonSerializable, Arrayable { abstract public static function getName(): string; diff --git a/src/Observability/Performance/Interfaces/Time.php b/src/Observability/Performance/Interfaces/Time.php index e2b284a..e948743 100644 --- a/src/Observability/Performance/Interfaces/Time.php +++ b/src/Observability/Performance/Interfaces/Time.php @@ -2,9 +2,11 @@ namespace RemotelyLiving\PHPDNS\Observability\Performance\Interfaces; +use DateTimeInterface; + interface Time { public function getMicrotime(): float; - public function now(): \DateTimeInterface; + public function now(): DateTimeInterface; } diff --git a/src/Observability/Performance/Profile.php b/src/Observability/Performance/Profile.php index 55041ed..d1843ac 100644 --- a/src/Observability/Performance/Profile.php +++ b/src/Observability/Performance/Profile.php @@ -5,6 +5,8 @@ use RemotelyLiving\PHPDNS\Observability\Performance\Interfaces\ProfileInterface; use RemotelyLiving\PHPDNS\Observability\Performance\Interfaces\Time; +use function memory_get_peak_usage; + final class Profile implements ProfileInterface { private string $transactionName; @@ -15,7 +17,7 @@ final class Profile implements ProfileInterface private int $peakMemoryUsage = 0; - private \RemotelyLiving\PHPDNS\Observability\Performance\Interfaces\Time $time; + private Time $time; public function __construct(string $transactionName, Time $time = null) { @@ -45,7 +47,7 @@ public function getElapsedSeconds(): float public function samplePeakMemoryUsage(): void { - $this->peakMemoryUsage = \memory_get_peak_usage(); + $this->peakMemoryUsage = memory_get_peak_usage(); } public function getPeakMemoryUsage(): int diff --git a/src/Observability/Performance/Timer.php b/src/Observability/Performance/Timer.php index a000345..d783962 100644 --- a/src/Observability/Performance/Timer.php +++ b/src/Observability/Performance/Timer.php @@ -2,17 +2,21 @@ namespace RemotelyLiving\PHPDNS\Observability\Performance; +use DateTimeImmutable; +use DateTimeInterface; use RemotelyLiving\PHPDNS\Observability\Performance\Interfaces\Time; +use function microtime; + final class Timer implements Time { public function getMicroTime(): float { - return \microtime(true); + return microtime(true); } - public function now(): \DateTimeInterface + public function now(): DateTimeInterface { - return new \DateTimeImmutable('now'); + return new DateTimeImmutable('now'); } } diff --git a/src/Observability/Subscribers/STDIOSubscriber.php b/src/Observability/Subscribers/STDIOSubscriber.php index 57f6d52..f4b8ae4 100644 --- a/src/Observability/Subscribers/STDIOSubscriber.php +++ b/src/Observability/Subscribers/STDIOSubscriber.php @@ -6,15 +6,18 @@ use RemotelyLiving\PHPDNS\Observability\Events\DNSQueryFailed; use RemotelyLiving\PHPDNS\Observability\Events\DNSQueryProfiled; use RemotelyLiving\PHPDNS\Observability\Events\ObservableEventAbstract; +use SplFileObject; use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use function json_encode; + final class STDIOSubscriber implements EventSubscriberInterface { - private \SplFileObject $STDOUT; + private SplFileObject $STDOUT; - private \SplFileObject $STDERR; + private SplFileObject $STDERR; - public function __construct(\SplFileObject $stdOut, \SplFileObject $stdErr) + public function __construct(SplFileObject $stdOut, SplFileObject $stdErr) { $this->STDOUT = $stdOut; $this->STDERR = $stdErr; @@ -31,16 +34,16 @@ public static function getSubscribedEvents() public function onDNSQueryFailed(ObservableEventAbstract $event): void { - $this->STDERR->fwrite(\json_encode($event, JSON_PRETTY_PRINT) . PHP_EOL); + $this->STDERR->fwrite(json_encode($event, JSON_PRETTY_PRINT) . PHP_EOL); } public function onDNSQueried(ObservableEventAbstract $event): void { - $this->STDOUT->fwrite(\json_encode($event, JSON_PRETTY_PRINT) . PHP_EOL); + $this->STDOUT->fwrite(json_encode($event, JSON_PRETTY_PRINT) . PHP_EOL); } public function onDNSQueryProfiled(ObservableEventAbstract $event): void { - $this->STDOUT->fwrite(\json_encode($event, JSON_PRETTY_PRINT) . PHP_EOL); + $this->STDOUT->fwrite(json_encode($event, JSON_PRETTY_PRINT) . PHP_EOL); } } diff --git a/src/Observability/Traits/Dispatcher.php b/src/Observability/Traits/Dispatcher.php index 65f2d8b..89c7346 100644 --- a/src/Observability/Traits/Dispatcher.php +++ b/src/Observability/Traits/Dispatcher.php @@ -2,14 +2,19 @@ namespace RemotelyLiving\PHPDNS\Observability\Traits; +use LogicException; +use ReflectionClass; +use ReflectionMethod; use RemotelyLiving\PHPDNS\Observability\Events\ObservableEventAbstract; use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use function call_user_func_array; + trait Dispatcher { - private ?\Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher = null; + private ?EventDispatcherInterface $dispatcher = null; public function setDispatcher(EventDispatcherInterface $dispatcher): void { @@ -28,14 +33,14 @@ public function addListener(string $eventName, callable $listener, int $priority public function dispatch(ObservableEventAbstract $event): void { - \call_user_func_array([$this->getDispatcher(), 'dispatch'], $this->getOrderedDispatcherArguments($event)); + call_user_func_array([$this->getDispatcher(), 'dispatch'], $this->getOrderedDispatcherArguments($event)); } private function getOrderedDispatcherArguments(ObservableEventAbstract $event): array { - $reflection = new \ReflectionClass($this->getDispatcher()); + $reflection = new ReflectionClass($this->getDispatcher()); - foreach ($reflection->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) { + foreach ($reflection->getMethods(ReflectionMethod::IS_PUBLIC) as $method) { if ($method->getName() !== 'dispatch') { continue; } @@ -48,7 +53,7 @@ private function getOrderedDispatcherArguments(ObservableEventAbstract $event): } } - throw new \LogicException('Could not determine argument order for dispatcher'); + throw new LogicException('Could not determine argument order for dispatcher'); } private function getDispatcher(): EventDispatcherInterface diff --git a/src/Observability/Traits/Logger.php b/src/Observability/Traits/Logger.php index 6dd176e..1d1d795 100644 --- a/src/Observability/Traits/Logger.php +++ b/src/Observability/Traits/Logger.php @@ -7,7 +7,7 @@ trait Logger { - private ?\Psr\Log\LoggerInterface $logger = null; + private ?LoggerInterface $logger = null; public function setLogger(LoggerInterface $logger): void { diff --git a/src/Observability/Traits/Profileable.php b/src/Observability/Traits/Profileable.php index 6ec24cb..4436321 100644 --- a/src/Observability/Traits/Profileable.php +++ b/src/Observability/Traits/Profileable.php @@ -7,7 +7,7 @@ trait Profileable { - private ?\RemotelyLiving\PHPDNS\Observability\Performance\ProfileFactory $profileFactory = null; + private ?ProfileFactory $profileFactory = null; public function createProfile(string $transactionName): Profile { diff --git a/src/Resolvers/Cached.php b/src/Resolvers/Cached.php index 45732ea..7cd84cf 100644 --- a/src/Resolvers/Cached.php +++ b/src/Resolvers/Cached.php @@ -9,6 +9,12 @@ use RemotelyLiving\PHPDNS\Resolvers\Traits\Time; use RemotelyLiving\PHPDNS\Resolvers\Interfaces\Resolver; +use function count; +use function max; +use function md5; +use function min; +use function sprintf; + final class Cached extends ResolverAbstract { use Time; @@ -16,9 +22,9 @@ final class Cached extends ResolverAbstract protected const DEFAULT_CACHE_TTL = 300; private const CACHE_KEY_TEMPLATE = '%s:%s:%s'; - private \Psr\Cache\CacheItemPoolInterface $cache; + private CacheItemPoolInterface $cache; - private \RemotelyLiving\PHPDNS\Resolvers\Interfaces\Resolver $resolver; + private Resolver $resolver; /** * Bump this number on breaking changes to invalidate cache @@ -72,7 +78,7 @@ protected function doQuery(Hostname $hostname, DNSRecordType $recordType): DNSRe private function buildCacheKey(Hostname $hostname, DNSRecordType $recordType): string { - return \md5(\sprintf(self::CACHE_KEY_TEMPLATE, self::NAMESPACE, (string)$hostname, (string)$recordType)); + return md5(sprintf(self::CACHE_KEY_TEMPLATE, self::NAMESPACE, (string)$hostname, (string)$recordType)); } private function extractLowestTTL(DNSRecordCollection $recordCollection): int @@ -89,7 +95,7 @@ private function extractLowestTTL(DNSRecordCollection $recordCollection): int $ttls[] = $record->getTTL(); } - return \count($ttls) ? \min($ttls) : self::DEFAULT_CACHE_TTL; + return count($ttls) ? min($ttls) : self::DEFAULT_CACHE_TTL; } /** @@ -105,7 +111,7 @@ private function unwrapResults(array $results): DNSRecordCollection */ foreach ($records as $key => $record) { $records[$key] = $record - ->setTTL(\max($record->getTTL() - ($this->getTimeStamp() - (int)$results['timestamp']), 0)); + ->setTTL(max($record->getTTL() - ($this->getTimeStamp() - (int)$results['timestamp']), 0)); } return $records; diff --git a/src/Resolvers/Chain.php b/src/Resolvers/Chain.php index 190ba06..431ddf5 100644 --- a/src/Resolvers/Chain.php +++ b/src/Resolvers/Chain.php @@ -15,6 +15,9 @@ use RemotelyLiving\PHPDNS\Resolvers\Interfaces\Resolver; use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use function json_encode; +use function shuffle; + final class Chain extends ResolverAbstract implements Interfaces\Chain { public const STRATEGY_FIRST_TO_FIND = 0; @@ -69,7 +72,7 @@ public function withConsensusResults(): Interfaces\Chain public function randomly(): Interfaces\Chain { $randomized = clone $this; - \shuffle($randomized->resolvers); + shuffle($randomized->resolvers); return $randomized; } @@ -122,7 +125,7 @@ protected function doQuery(Hostname $hostname, DNSRecordType $recordType): DNSRe } catch (Exception $e) { $this->getLogger()->error( 'Something went wrong in the chain of resolvers', - ['exception' => \json_encode($e), 'resolver' => $resolver->getName()] + ['exception' => json_encode($e), 'resolver' => $resolver->getName()] ); continue; } diff --git a/src/Resolvers/CloudFlare.php b/src/Resolvers/CloudFlare.php index d3d28b1..c21597d 100644 --- a/src/Resolvers/CloudFlare.php +++ b/src/Resolvers/CloudFlare.php @@ -2,9 +2,9 @@ namespace RemotelyLiving\PHPDNS\Resolvers; +use Generator; use GuzzleHttp\Client; use GuzzleHttp\ClientInterface; -use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Promise\EachPromise; use GuzzleHttp\Psr7\Response; use RemotelyLiving\PHPDNS\Entities\DNSRecordCollection; @@ -12,6 +12,11 @@ use RemotelyLiving\PHPDNS\Entities\Hostname; use RemotelyLiving\PHPDNS\Mappers\CloudFlare as CloudFlareMapper; use RemotelyLiving\PHPDNS\Resolvers\Exceptions\QueryFailure; +use Throwable; + +use function array_merge; +use function http_build_query; +use function json_decode; final class CloudFlare extends ResolverAbstract { @@ -28,7 +33,7 @@ final class CloudFlare extends ResolverAbstract ], ]; - private \GuzzleHttp\ClientInterface $http; + private ClientInterface $http; private CloudFlareMapper $mapper; @@ -53,7 +58,7 @@ protected function doQuery(Hostname $hostname, DNSRecordType $recordType): DNSRe return (!$recordType->isA(DNSRecordType::TYPE_ANY)) ? $this->doApiQuery($hostname, $recordType) : $this->doAnyApiQuery($hostname); - } catch (\Throwable $e) { + } catch (Throwable $e) { throw new QueryFailure("Unable to query CloudFlare API", 0, $e); } } @@ -67,12 +72,12 @@ private function doAnyApiQuery(Hostname $hostname): DNSRecordCollection $eachPromise = new EachPromise($this->generateEachTypeQuery($hostname), [ 'concurrency' => 4, 'fulfilled' => function (Response $response) use (&$results) { - $results = \array_merge( + $results = array_merge( $results, - $this->parseResult((array) \json_decode((string)$response->getBody(), true)) + $this->parseResult((array) json_decode((string)$response->getBody(), true)) ); }, - 'rejected' => function (\Throwable $e): void { + 'rejected' => function (Throwable $e): void { throw $e; }, ]); @@ -82,7 +87,7 @@ private function doAnyApiQuery(Hostname $hostname): DNSRecordCollection return $this->mapResults($this->mapper, $results); } - private function generateEachTypeQuery(Hostname $hostname): \Generator + private function generateEachTypeQuery(Hostname $hostname): Generator { foreach (DNSRecordType::VALID_TYPES as $type) { if ($type === DNSRecordType::TYPE_ANY) { @@ -91,7 +96,7 @@ private function generateEachTypeQuery(Hostname $hostname): \Generator yield $this->http->requestAsync( 'GET', - '/dns-query?' . \http_build_query(['name' => (string)$hostname, 'type' => $type]), + '/dns-query?' . http_build_query(['name' => (string)$hostname, 'type' => $type]), $this->options ); } @@ -99,8 +104,8 @@ private function generateEachTypeQuery(Hostname $hostname): \Generator private function doApiQuery(Hostname $hostname, DNSRecordType $type): DNSRecordCollection { - $url = '/dns-query?' . \http_build_query(['name' => (string)$hostname, 'type' => (string)$type]); - $decoded = (array)\json_decode( + $url = '/dns-query?' . http_build_query(['name' => (string)$hostname, 'type' => (string)$type]); + $decoded = (array)json_decode( (string)$this->http->requestAsync('GET', $url, $this->options)->wait(true)->getBody(), true ); diff --git a/src/Resolvers/Dig.php b/src/Resolvers/Dig.php index 9c49841..089a4ae 100644 --- a/src/Resolvers/Dig.php +++ b/src/Resolvers/Dig.php @@ -8,6 +8,13 @@ use RemotelyLiving\PHPDNS\Factories\SpatieDNS; use RemotelyLiving\PHPDNS\Mappers\Dig as DigMapper; use RemotelyLiving\PHPDNS\Resolvers\Exceptions\QueryFailure; +use Throwable; + +use function array_slice; +use function explode; +use function implode; +use function preg_replace; +use function trim; final class Dig extends ResolverAbstract { @@ -24,11 +31,11 @@ final class Dig extends ResolverAbstract DNSRecordType::TYPE_NAPTR, ]; - private \RemotelyLiving\PHPDNS\Factories\SpatieDNS $spatieDNSFactory; + private SpatieDNS $spatieDNSFactory; private DigMapper $mapper; - private ?\RemotelyLiving\PHPDNS\Entities\Hostname $nameserver; + private ?Hostname $nameserver; public function __construct( SpatieDNS $spatieDNSFactory = null, @@ -52,7 +59,7 @@ protected function doQuery(Hostname $hostname, DNSRecordType $recordType): DNSRe $response = ($recordType->equals(DNSRecordType::createANY())) ? $dig->getRecords(...self::SUPPORTED_QUERY_TYPES) : $dig->getRecords((string) $recordType); - } catch (\Throwable $e) { + } catch (Throwable $e) { throw new QueryFailure($e->getMessage(), 0, $e); } @@ -62,13 +69,13 @@ protected function doQuery(Hostname $hostname, DNSRecordType $recordType): DNSRe private static function parseDigResponseToRows(string $digResponse): array { $rows = []; - foreach (\explode(PHP_EOL, self::normalizeColumns($digResponse)) as $line) { - if (!\trim($line)) { + foreach (explode(PHP_EOL, self::normalizeColumns($digResponse)) as $line) { + if (!trim($line)) { continue; } - $columns = \explode(' ', $line); - $rows[] = [$columns[0], $columns[1], $columns[2], $columns[3], \implode(' ', \array_slice($columns, 4))]; + $columns = explode(' ', $line); + $rows[] = [$columns[0], $columns[1], $columns[2], $columns[3], implode(' ', array_slice($columns, 4))]; } return $rows; @@ -76,10 +83,10 @@ private static function parseDigResponseToRows(string $digResponse): array private static function normalizeColumns(string $response): string { - $keysRemoved = \preg_replace('/;(.*)/m', ' ', \trim($response)); - $tabsRemoved = \preg_replace('/(\t)/m', ' ', (string) $keysRemoved); - $breaksRemoved = \preg_replace('/\s\s/m', '', (string) $tabsRemoved); - return (string) \preg_replace('/(\(\s|(\s\)))/m', '', (string) $breaksRemoved); + $keysRemoved = preg_replace('/;(.*)/m', ' ', trim($response)); + $tabsRemoved = preg_replace('/(\t)/m', ' ', (string) $keysRemoved); + $breaksRemoved = preg_replace('/\s\s/m', '', (string) $tabsRemoved); + return (string) preg_replace('/(\(\s|(\s\)))/m', '', (string) $breaksRemoved); } private static function isSupportedQueryType(DNSRecordType $type): bool diff --git a/src/Resolvers/GoogleDNS.php b/src/Resolvers/GoogleDNS.php index d7504bd..456eaf0 100644 --- a/src/Resolvers/GoogleDNS.php +++ b/src/Resolvers/GoogleDNS.php @@ -12,6 +12,10 @@ use RemotelyLiving\PHPDNS\Entities\Hostname; use RemotelyLiving\PHPDNS\Mappers\GoogleDNS as GoogleDNSMapper; use RemotelyLiving\PHPDNS\Resolvers\Exceptions\QueryFailure; +use Throwable; + +use function http_build_query; +use function json_decode; final class GoogleDNS extends ResolverAbstract { @@ -28,7 +32,7 @@ final class GoogleDNS extends ResolverAbstract ], ]; - private \GuzzleHttp\ClientInterface $http; + private ClientInterface $http; private GoogleDNSMapper $mapper; @@ -81,12 +85,12 @@ protected function doQuery(Hostname $hostname, DNSRecordType $recordType): DNSRe private function doApiQuery(array $query = []): array { try { - $response = $this->http->request('GET', '/resolve?' . \http_build_query($query), $this->options); - } catch (RequestException $e) { + $response = $this->http->request('GET', '/resolve?' . http_build_query($query), $this->options); + } catch (Throwable $e) { throw new QueryFailure("Unable to query GoogleDNS API", 0, $e); } - $result = (array) \json_decode((string)$response->getBody(), true); + $result = (array) json_decode((string)$response->getBody(), true); if (isset($result['Answer'])) { return $result['Answer']; diff --git a/src/Resolvers/LocalSystem.php b/src/Resolvers/LocalSystem.php index b702747..70f4797 100644 --- a/src/Resolvers/LocalSystem.php +++ b/src/Resolvers/LocalSystem.php @@ -13,7 +13,7 @@ final class LocalSystem extends ResolverAbstract implements ReverseDNSQuery { - private \RemotelyLiving\PHPDNS\Services\Interfaces\LocalSystemDNS $systemDNS; + private LocalSystemDNS $systemDNS; private LocalMapper $mapper; diff --git a/src/Resolvers/ResolverAbstract.php b/src/Resolvers/ResolverAbstract.php index 95de7ac..84fdf1e 100644 --- a/src/Resolvers/ResolverAbstract.php +++ b/src/Resolvers/ResolverAbstract.php @@ -18,6 +18,12 @@ use RemotelyLiving\PHPDNS\Resolvers\Exceptions\QueryFailure; use RemotelyLiving\PHPDNS\Resolvers\Interfaces\ObservableResolver; +use function array_map; +use function array_pop; +use function explode; +use function get_class; +use function json_encode; + abstract class ResolverAbstract implements ObservableResolver { use Logger; @@ -33,8 +39,8 @@ abstract class ResolverAbstract implements ObservableResolver public function getName(): string { if ($this->name === null) { - $explodedClass = \explode('\\', \get_class($this)); - $this->name = (string)\array_pop($explodedClass); + $explodedClass = explode('\\', get_class($this)); + $this->name = (string)array_pop($explodedClass); } return $this->name; @@ -96,7 +102,7 @@ public function getRecords(string $hostname, string $recordType = null): DNSReco $this->dispatch($dnsQueryFailureEvent); $this->getLogger()->error( 'DNS query failed', - [self::EVENT => \json_encode($dnsQueryFailureEvent), 'exception' => $e] + [self::EVENT => json_encode($dnsQueryFailureEvent), 'exception' => $e] ); throw $e; @@ -105,19 +111,19 @@ public function getRecords(string $hostname, string $recordType = null): DNSReco $profile->samplePeakMemoryUsage(); $dnsQueryProfiledEvent = new DNSQueryProfiled($profile); $this->dispatch($dnsQueryProfiledEvent); - $this->getLogger()->info('DNS query profiled', [self::EVENT => \json_encode($dnsQueryProfiledEvent)]); + $this->getLogger()->info('DNS query profiled', [self::EVENT => json_encode($dnsQueryProfiledEvent)]); } $dnsQueriedEvent = new DNSQueried($this, $hostname, $recordType, $result); $this->dispatch($dnsQueriedEvent); - $this->getLogger()->info('DNS queried', [self::EVENT => \json_encode($dnsQueriedEvent)]); + $this->getLogger()->info('DNS queried', [self::EVENT => json_encode($dnsQueriedEvent)]); return $result; } public function mapResults(MapperInterface $mapper, array $results): DNSRecordCollection { $collection = new DNSRecordCollection(); - \array_map(function (array $fields) use (&$collection, $mapper) { + array_map(function (array $fields) use (&$collection, $mapper) { try { $collection[] = $mapper->mapFields($fields)->toDNSRecord(); } catch (InvalidArgumentException $e) { diff --git a/src/Resolvers/Traits/Time.php b/src/Resolvers/Traits/Time.php index c4170a8..a56374a 100644 --- a/src/Resolvers/Traits/Time.php +++ b/src/Resolvers/Traits/Time.php @@ -2,11 +2,13 @@ namespace RemotelyLiving\PHPDNS\Resolvers\Traits; +use DateTimeImmutable; + trait Time { - private ?\DateTimeImmutable $dateTimeImmutable = null; + private ?DateTimeImmutable $dateTimeImmutable = null; - public function setDateTimeImmutable(\DateTimeImmutable $dateTimeImmutable): void + public function setDateTimeImmutable(DateTimeImmutable $dateTimeImmutable): void { $this->dateTimeImmutable = $dateTimeImmutable; } @@ -16,10 +18,10 @@ public function getTimeStamp(): int return $this->getNewDateTimeImmutable()->getTimestamp(); } - private function getNewDateTimeImmutable(): \DateTimeImmutable + private function getNewDateTimeImmutable(): DateTimeImmutable { if (!$this->dateTimeImmutable) { - $this->dateTimeImmutable = new \DateTimeImmutable(); + $this->dateTimeImmutable = new DateTimeImmutable(); } return /** @scrutinizer ignore-type */ $this->dateTimeImmutable diff --git a/src/Services/LocalSystemDNS.php b/src/Services/LocalSystemDNS.php index cb62f6e..7d73a9a 100644 --- a/src/Services/LocalSystemDNS.php +++ b/src/Services/LocalSystemDNS.php @@ -6,6 +6,9 @@ use RemotelyLiving\PHPDNS\Resolvers\Exceptions\ReverseLookupFailure; use RemotelyLiving\PHPDNS\Services\Interfaces\LocalSystemDNS as LocalSystemDNSInterface; +use function dns_get_record; +use function gethostbyaddr; + final class LocalSystemDNS implements LocalSystemDNSInterface { /** @@ -13,7 +16,7 @@ final class LocalSystemDNS implements LocalSystemDNSInterface */ public function getRecord(string $hostname, int $type): array { - $results = @\dns_get_record($hostname, $type); + $results = @dns_get_record($hostname, $type); // this is untestable without creating a system networking failure // @codeCoverageIgnoreStart @@ -30,7 +33,7 @@ public function getRecord(string $hostname, int $type): array */ public function getHostnameByAddress(string $IPAddress): string { - $hostname = @\gethostbyaddr($IPAddress); + $hostname = @gethostbyaddr($IPAddress); if ($hostname === $IPAddress || $hostname === false) { throw new ReverseLookupFailure(); diff --git a/tests/Integration/BaseTestAbstract.php b/tests/Integration/BaseTestAbstract.php index 6c5ee1e..13cd1cd 100644 --- a/tests/Integration/BaseTestAbstract.php +++ b/tests/Integration/BaseTestAbstract.php @@ -14,6 +14,7 @@ use RemotelyLiving\PHPDNS\Resolvers\LocalSystem; use RemotelyLiving\PHPDNS\Resolvers\ResolverAbstract; use RemotelyLiving\PHPDNS\Services\LocalSystemDNS; +use SplFileObject; use Symfony\Component\Cache\Adapter\FilesystemAdapter; use Symfony\Component\EventDispatcher\EventSubscriberInterface; @@ -66,7 +67,7 @@ protected function createCachedResolver(CacheItemPoolInterface $cachePool): Cach protected function createStdIOSubscriber(): EventSubscriberInterface { - return new STDIOSubscriber(new \SplFileObject('php://stdout'), new \SplFileObject('php://stderr')); + return new STDIOSubscriber(new SplFileObject('php://stdout'), new SplFileObject('php://stderr')); } protected function attachTestSubscribers(ResolverAbstract $resolver): void diff --git a/tests/Integration/ServicesTest.php b/tests/Integration/ServicesTest.php index b3f5176..be3cf83 100644 --- a/tests/Integration/ServicesTest.php +++ b/tests/Integration/ServicesTest.php @@ -4,6 +4,8 @@ use RemotelyLiving\PHPDNS\Resolvers\Exceptions\ReverseLookupFailure; +use const DNS_ALL; + class ServicesTest extends BaseTestAbstract { /** @@ -13,10 +15,10 @@ public function localDNSServiceProvidesRecords(): void { $localDNS = $this->createLocalSystemDNS(); - $records = $localDNS->getRecord('google.com', \DNS_ALL); + $records = $localDNS->getRecord('google.com', DNS_ALL); $this->assertNotEmpty($records); - $resultOfBadOperation = $localDNS->getRecord('l', \DNS_ALL); + $resultOfBadOperation = $localDNS->getRecord('l', DNS_ALL); $this->assertEquals([], $resultOfBadOperation); } diff --git a/tests/Unit/BaseTestAbstract.php b/tests/Unit/BaseTestAbstract.php index 7e068df..fbf65a6 100644 --- a/tests/Unit/BaseTestAbstract.php +++ b/tests/Unit/BaseTestAbstract.php @@ -2,15 +2,19 @@ namespace RemotelyLiving\PHPDNS\Tests\Unit; +use JsonSerializable; use PHPUnit\Framework\TestCase; use RemotelyLiving\PHPDNS\Entities\Interfaces\Arrayable; use RemotelyLiving\PHPDNS\Entities\Interfaces\Serializable; +use function serialize; +use function unserialize; + abstract class BaseTestAbstract extends TestCase { protected function assertSerializable(Serializable $serializable) { - $this->assertEquals($serializable, \unserialize(\serialize($serializable))); + $this->assertEquals($serializable, unserialize(serialize($serializable))); } protected function assertArrayableAndEquals(array $expected, Arrayable $arrayable) @@ -18,7 +22,7 @@ protected function assertArrayableAndEquals(array $expected, Arrayable $arrayabl $this->assertEquals($expected, $arrayable->toArray()); } - protected function assertJsonSerializeableAndEquals(array $expected, \JsonSerializable $jsonSerializeable) + protected function assertJsonSerializeableAndEquals(array $expected, JsonSerializable $jsonSerializeable) { $this->assertEquals($expected, $jsonSerializeable->jsonSerialize()); } diff --git a/tests/Unit/Entities/CAADataTest.php b/tests/Unit/Entities/CAADataTest.php index bcc1b5e..7a52a18 100644 --- a/tests/Unit/Entities/CAADataTest.php +++ b/tests/Unit/Entities/CAADataTest.php @@ -6,6 +6,9 @@ use RemotelyLiving\PHPDNS\Exceptions; use RemotelyLiving\PHPDNS\Tests\Unit\BaseTestAbstract; +use function serialize; +use function unserialize; + class CAADataTest extends BaseTestAbstract { @@ -64,7 +67,7 @@ public function isJsonSerializable(): void public function isSerializable(): void { $this->assertSerializable($this->CAAData); - $this->assertEquals($this->CAAData, \unserialize(\serialize($this->CAAData))); + $this->assertEquals($this->CAAData, unserialize(serialize($this->CAAData))); } /** diff --git a/tests/Unit/Entities/CNAMEDataTest.php b/tests/Unit/Entities/CNAMEDataTest.php index d4be73e..cf903a1 100644 --- a/tests/Unit/Entities/CNAMEDataTest.php +++ b/tests/Unit/Entities/CNAMEDataTest.php @@ -6,6 +6,9 @@ use RemotelyLiving\PHPDNS\Entities\Hostname; use RemotelyLiving\PHPDNS\Tests\Unit\BaseTestAbstract; +use function serialize; +use function unserialize; + class CNAMEDataTest extends BaseTestAbstract { /** @@ -71,7 +74,7 @@ public function isSerializable(): void public function isStringable(): void { $this->assertStringableAndEquals('google.com.', $this->CNAMEData); - $this->assertEquals($this->CNAMEData, \unserialize(\serialize($this->CNAMEData))); + $this->assertEquals($this->CNAMEData, unserialize(serialize($this->CNAMEData))); } /** diff --git a/tests/Unit/Entities/DNSRecordCollectionTest.php b/tests/Unit/Entities/DNSRecordCollectionTest.php index c05f1a8..d5702d6 100644 --- a/tests/Unit/Entities/DNSRecordCollectionTest.php +++ b/tests/Unit/Entities/DNSRecordCollectionTest.php @@ -2,12 +2,15 @@ namespace RemotelyLiving\PHPDNS\Tests\Unit\Entities; +use Countable; +use Iterator; use RemotelyLiving\PHPDNS\Entities\DNSRecord; use RemotelyLiving\PHPDNS\Entities\DNSRecordCollection; use RemotelyLiving\PHPDNS\Entities\DNSRecordType; use RemotelyLiving\PHPDNS\Entities\Interfaces\Arrayable; use RemotelyLiving\PHPDNS\Exceptions\InvalidArgumentException; use RemotelyLiving\PHPDNS\Tests\Unit\BaseTestAbstract; +use Traversable; class DNSRecordCollectionTest extends BaseTestAbstract { @@ -105,9 +108,9 @@ public function hasARecord(): void */ public function isCountableTraversableIteratable(): void { - $this->assertInstanceOf(\Traversable::class, $this->dnsRecordCollection); - $this->assertInstanceOf(\Countable::class, $this->dnsRecordCollection); - $this->assertInstanceOf(\Iterator::class, $this->dnsRecordCollection); + $this->assertInstanceOf(Traversable::class, $this->dnsRecordCollection); + $this->assertInstanceOf(Countable::class, $this->dnsRecordCollection); + $this->assertInstanceOf(Iterator::class, $this->dnsRecordCollection); foreach ($this->dnsRecordCollection as $record) { $this->assertInstanceOf(DNSRecord::class, $record); diff --git a/tests/Unit/Entities/MXDataTest.php b/tests/Unit/Entities/MXDataTest.php index 2f383c3..d2a46c9 100644 --- a/tests/Unit/Entities/MXDataTest.php +++ b/tests/Unit/Entities/MXDataTest.php @@ -6,6 +6,9 @@ use RemotelyLiving\PHPDNS\Entities\MXData; use RemotelyLiving\PHPDNS\Tests\Unit\BaseTestAbstract; +use function serialize; +use function unserialize; + class MXDataTest extends BaseTestAbstract { /** @@ -68,7 +71,7 @@ public function isJsonSerializeable(): void public function isSerializable(): void { $this->assertSerializable($this->MXData); - $this->assertEquals($this->MXData, \unserialize(\serialize($this->MXData))); + $this->assertEquals($this->MXData, unserialize(serialize($this->MXData))); } /** diff --git a/tests/Unit/Entities/NSDataTest.php b/tests/Unit/Entities/NSDataTest.php index 24f83ba..26799b0 100644 --- a/tests/Unit/Entities/NSDataTest.php +++ b/tests/Unit/Entities/NSDataTest.php @@ -6,6 +6,9 @@ use RemotelyLiving\PHPDNS\Entities\NSData; use RemotelyLiving\PHPDNS\Tests\Unit\BaseTestAbstract; +use function serialize; +use function unserialize; + class NSDataTest extends BaseTestAbstract { /** @@ -57,7 +60,7 @@ public function isJsonSerializeable(): void public function isSerializable(): void { $this->assertSerializable($this->NSData); - $this->assertEquals($this->NSData, \unserialize(\serialize($this->NSData))); + $this->assertEquals($this->NSData, unserialize(serialize($this->NSData))); } /** diff --git a/tests/Unit/Entities/SOADataTest.php b/tests/Unit/Entities/SOADataTest.php index 7b3b071..104e241 100644 --- a/tests/Unit/Entities/SOADataTest.php +++ b/tests/Unit/Entities/SOADataTest.php @@ -6,6 +6,9 @@ use RemotelyLiving\PHPDNS\Entities\SOAData; use RemotelyLiving\PHPDNS\Tests\Unit\BaseTestAbstract; +use function serialize; +use function unserialize; + class SOADataTest extends BaseTestAbstract { /** @@ -119,7 +122,7 @@ public function isJsonSerializeable(): void public function isSerializable(): void { $this->assertSerializable($this->SOAData); - $this->assertEquals($this->SOAData, \unserialize(\serialize($this->SOAData))); + $this->assertEquals($this->SOAData, unserialize(serialize($this->SOAData))); } /** diff --git a/tests/Unit/Entities/SRVDataTest.php b/tests/Unit/Entities/SRVDataTest.php index c51eb92..2b67ca3 100644 --- a/tests/Unit/Entities/SRVDataTest.php +++ b/tests/Unit/Entities/SRVDataTest.php @@ -6,6 +6,9 @@ use RemotelyLiving\PHPDNS\Entities\SRVData; use RemotelyLiving\PHPDNS\Tests\Unit\BaseTestAbstract; +use function serialize; +use function unserialize; + class SRVDataTest extends BaseTestAbstract { /** @@ -86,7 +89,7 @@ public function isJsonSerializeable(): void public function isSerializable(): void { $this->assertSerializable($this->SRVData); - $this->assertEquals($this->SRVData, \unserialize(\serialize($this->SRVData))); + $this->assertEquals($this->SRVData, unserialize(serialize($this->SRVData))); } /** diff --git a/tests/Unit/Entities/TXTDataTest.php b/tests/Unit/Entities/TXTDataTest.php index 21ebd72..366f3e9 100644 --- a/tests/Unit/Entities/TXTDataTest.php +++ b/tests/Unit/Entities/TXTDataTest.php @@ -5,6 +5,9 @@ use RemotelyLiving\PHPDNS\Entities\TXTData; use RemotelyLiving\PHPDNS\Tests\Unit\BaseTestAbstract; +use function serialize; +use function unserialize; + class TXTDataTest extends BaseTestAbstract { /** @@ -55,7 +58,7 @@ public function isJsonSerializeable(): void public function isSerializable(): void { $this->assertSerializable($this->TXTData); - $this->assertEquals($this->TXTData, \unserialize(\serialize($this->TXTData))); + $this->assertEquals($this->TXTData, unserialize(serialize($this->TXTData))); } /** diff --git a/tests/Unit/Exceptions/ExceptionTest.php b/tests/Unit/Exceptions/ExceptionTest.php index a9e3d83..a51bbcb 100644 --- a/tests/Unit/Exceptions/ExceptionTest.php +++ b/tests/Unit/Exceptions/ExceptionTest.php @@ -2,6 +2,7 @@ namespace RemotelyLiving\PHPDNS\Tests\Unit\Exceptions; +use JsonSerializable; use RemotelyLiving\PHPDNS\Exceptions\Exception; use RemotelyLiving\PHPDNS\Tests\Unit\BaseTestAbstract; @@ -14,7 +15,7 @@ public function isJsonSerializable(): void { $exception = new Exception('The exception', 123); - $this->assertInstanceOf(\JsonSerializable::class, $exception); + $this->assertInstanceOf(JsonSerializable::class, $exception); $jsonReady = $exception->jsonSerialize(); diff --git a/tests/Unit/Observability/Events/DNSQueryFailedTest.php b/tests/Unit/Observability/Events/DNSQueryFailedTest.php index 677a473..b200668 100644 --- a/tests/Unit/Observability/Events/DNSQueryFailedTest.php +++ b/tests/Unit/Observability/Events/DNSQueryFailedTest.php @@ -2,6 +2,7 @@ namespace RemotelyLiving\PHPDNS\Tests\Unit\Observability\Events; +use JsonSerializable; use RemotelyLiving\PHPDNS\Entities\DNSRecordType; use RemotelyLiving\PHPDNS\Entities\Hostname; use RemotelyLiving\PHPDNS\Entities\Interfaces\Arrayable; @@ -82,7 +83,7 @@ public function isArrayable(): void ]; $this->assertInstanceOf(Arrayable::class, $this->DNSQueryFailed); - $this->assertInstanceOf(\JsonSerializable::class, $this->error); + $this->assertInstanceOf(JsonSerializable::class, $this->error); $this->assertEquals($expected, $this->DNSQueryFailed->toArray()); } } diff --git a/tests/Unit/Observability/Events/ObservableEventAbstractTest.php b/tests/Unit/Observability/Events/ObservableEventAbstractTest.php index 90b79dc..6d45b59 100644 --- a/tests/Unit/Observability/Events/ObservableEventAbstractTest.php +++ b/tests/Unit/Observability/Events/ObservableEventAbstractTest.php @@ -2,6 +2,7 @@ namespace RemotelyLiving\PHPDNS\Tests\Unit\Observability\Events; +use JsonSerializable; use RemotelyLiving\PHPDNS\Entities\Interfaces\Arrayable; use RemotelyLiving\PHPDNS\Observability\Events\ObservableEventAbstract; use RemotelyLiving\PHPDNS\Tests\Unit\BaseTestAbstract; @@ -53,7 +54,7 @@ public function isArrayable(): void */ public function isJsonSerializable(): void { - $this->assertInstanceOf(\JsonSerializable::class, $this->event); + $this->assertInstanceOf(JsonSerializable::class, $this->event); $this->assertEquals(['the name' => ['beep' => 'boop']], $this->event->jsonSerialize()); } } diff --git a/tests/Unit/Observability/Performance/TimerTest.php b/tests/Unit/Observability/Performance/TimerTest.php index 746c2c1..a0b7abf 100644 --- a/tests/Unit/Observability/Performance/TimerTest.php +++ b/tests/Unit/Observability/Performance/TimerTest.php @@ -2,6 +2,7 @@ namespace RemotelyLiving\PHPDNS\Tests\Unit\Observability\Performance; +use DateTimeInterface; use RemotelyLiving\PHPDNS\Observability\Performance\Timer; use RemotelyLiving\PHPDNS\Tests\Unit\BaseTestAbstract; @@ -28,6 +29,6 @@ public function getsNowAndMicroTime(): void $this->assertGreaterThan(0, $this->timer->getMicroTime()); $this->assertTrue(is_float($this->timer->getMicroTime())); - $this->assertInstanceOf(\DateTimeInterface::class, $this->timer->now()); + $this->assertInstanceOf(DateTimeInterface::class, $this->timer->now()); } } diff --git a/tests/Unit/Observability/Subscribers/STDIOSubscriberTest.php b/tests/Unit/Observability/Subscribers/STDIOSubscriberTest.php index b58c228..af66417 100644 --- a/tests/Unit/Observability/Subscribers/STDIOSubscriberTest.php +++ b/tests/Unit/Observability/Subscribers/STDIOSubscriberTest.php @@ -8,6 +8,7 @@ use RemotelyLiving\PHPDNS\Observability\Events\ObservableEventAbstract; use RemotelyLiving\PHPDNS\Observability\Subscribers\STDIOSubscriber; use RemotelyLiving\PHPDNS\Tests\Unit\BaseTestAbstract; +use SplFileObject; class STDIOSubscriberTest extends BaseTestAbstract { @@ -40,12 +41,12 @@ protected function setUp(): void { parent::setUp(); - $this->STDOut = $this->getMockBuilder(\SplFileObject::class) + $this->STDOut = $this->getMockBuilder(SplFileObject::class) ->setConstructorArgs(['php://memory']) ->setMethods(['fwrite']) ->getMock(); - $this->STDErr = $this->getMockBuilder(\SplFileObject::class) + $this->STDErr = $this->getMockBuilder(SplFileObject::class) ->setConstructorArgs(['php://memory']) ->setMethods(['fwrite']) ->getMock(); diff --git a/tests/Unit/Resolvers/CachedTest.php b/tests/Unit/Resolvers/CachedTest.php index a70b33f..b2a9e12 100644 --- a/tests/Unit/Resolvers/CachedTest.php +++ b/tests/Unit/Resolvers/CachedTest.php @@ -2,6 +2,7 @@ namespace RemotelyLiving\PHPDNS\Tests\Unit\Resolvers; +use DateTimeImmutable; use Psr\Cache\CacheItemInterface; use Psr\Cache\CacheItemPoolInterface; use RemotelyLiving\PHPDNS\Entities\DNSRecord; @@ -65,7 +66,7 @@ class CachedTest extends BaseTestAbstract protected function setUp(): void { $this->timestamp = time(); - $this->dateTimeImmutable = $this->createMock(\DateTimeImmutable::class); + $this->dateTimeImmutable = $this->createMock(DateTimeImmutable::class); $this->dateTimeImmutable->method('setTimeStamp') ->willReturn($this->dateTimeImmutable); $this->dateTimeImmutable->method('getTimeStamp') diff --git a/tests/Unit/Resolvers/CloudFlareTest.php b/tests/Unit/Resolvers/CloudFlareTest.php index e3b7aa1..79f5cc0 100644 --- a/tests/Unit/Resolvers/CloudFlareTest.php +++ b/tests/Unit/Resolvers/CloudFlareTest.php @@ -7,6 +7,7 @@ use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Exception\ServerException; +use GuzzleHttp\Exception\TransferException; use GuzzleHttp\Promise\FulfilledPromise; use GuzzleHttp\Promise\Promise; use GuzzleHttp\Promise\RejectedPromise; @@ -23,6 +24,7 @@ use RemotelyLiving\PHPDNS\Resolvers\GoogleDNS; use RemotelyLiving\PHPDNS\Resolvers\ResolverAbstract; use RemotelyLiving\PHPDNS\Tests\Unit\BaseTestAbstract; +use function json_decode; // @codingStandardsIgnoreFile class CloudFlareTest extends BaseTestAbstract @@ -126,7 +128,7 @@ public function getsANYRecords() : void * @test * @dataProvider httpExceptionProvider */ - public function rethrowsAllHTTPExceptionsAsQueryFailures(RequestException $e) + public function rethrowsAllHTTPExceptionsAsQueryFailures(TransferException $e) { $this->expectException(QueryFailure::class); @@ -164,7 +166,7 @@ public function rethrowsAllHTTPExceptionsAsQueryFailuresForANYQuery(RequestExcep public function httpExceptionProvider(): array { return [ - [$this->createMock(ConnectException::class)], + [$this->createMock(RequestException::class)], [$this->createMock(ClientException::class)], [$this->createMock(ServerException::class)], ]; @@ -195,7 +197,7 @@ public static function buildResponseBasedOnType(int $type): string { $json = '{"Status":0,"TC":false,"RD":true,"RA":true,"AD":true,"CD":false,"Question":[{"name":"example.com","type":28}],"Answer":[{"name":"facebook.com.","type":28,"TTL":1726,"data":"2606:2800:220:1:248:1893:25c8:1946"}]}'; - $decoded = \json_decode($json, true); + $decoded = json_decode($json, true); $decoded['Answer'][0]['type'] = $type; return json_encode($decoded); diff --git a/tests/Unit/Resolvers/DigTest.php b/tests/Unit/Resolvers/DigTest.php index 7d56e82..f1b3df0 100644 --- a/tests/Unit/Resolvers/DigTest.php +++ b/tests/Unit/Resolvers/DigTest.php @@ -1,6 +1,7 @@ spatieDNS->method('getRecords') ->with(...Resolvers\Dig::SUPPORTED_QUERY_TYPES) - ->willThrowException(new \InvalidArgumentException('The message')); + ->willThrowException(new InvalidArgumentException('The message')); $this->dig->getRecords($this->hostname); } diff --git a/tests/Unit/Resolvers/GoogleDNSTest.php b/tests/Unit/Resolvers/GoogleDNSTest.php index 7776923..6beed98 100644 --- a/tests/Unit/Resolvers/GoogleDNSTest.php +++ b/tests/Unit/Resolvers/GoogleDNSTest.php @@ -16,6 +16,8 @@ use RemotelyLiving\PHPDNS\Resolvers\GoogleDNS; use RemotelyLiving\PHPDNS\Resolvers\ResolverAbstract; use RemotelyLiving\PHPDNS\Tests\Unit\BaseTestAbstract; +use Throwable; +use function json_decode; // @codingStandardsIgnoreFile class GoogleDNSTest extends BaseTestAbstract @@ -80,7 +82,7 @@ public function getsRecords(string $method, Hostname $hostname, DNSRecordType $t * @test * @dataProvider httpExceptionProvider */ - public function getsRecordsAndThrowsQueryExceptionOnFailures(\Throwable $e) + public function getsRecordsAndThrowsQueryExceptionOnFailures(Throwable $e) { $this->expectException(QueryFailure::class); @@ -128,7 +130,7 @@ public static function buildResponseBasedOnType(int $type): string { $json = '{"Status":0,"TC":false,"RD":true,"RA":true,"AD":true,"CD":false,"Question":[{"name":"example.com","type":28}],"Answer":[{"name":"facebook.com.","type":28,"TTL":1726,"data":"2606:2800:220:1:248:1893:25c8:1946"}]}'; - $decoded = \json_decode($json, true); + $decoded = json_decode($json, true); $decoded['Answer'][0]['type'] = $type; return json_encode($decoded);