From 8b9620470bd3d367a397f749c365da60eeb1cc28 Mon Sep 17 00:00:00 2001 From: Lenny ROUANET Date: Fri, 21 Oct 2022 19:49:16 +0200 Subject: [PATCH] Hello world ! --- .gitignore | 1 + README.md | 2 +- component/Data/EmailServiceProvider.php | 119 +- component/Data/TrashMailBoxService.php | 1317 ++++++++++++----------- component/Error/InvalidFormat.php | 9 +- component/Service/DnsRecord.php | 99 +- component/Service/ServiceProvided.php | 35 +- composer.json | 6 +- test/Service/DnsRecordTest.php | 76 +- test/Service/ServiceProvidedTest.php | 128 +-- 10 files changed, 906 insertions(+), 886 deletions(-) diff --git a/.gitignore b/.gitignore index d10a988..a0592b0 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ vendor/* # Dev .DS_Store .nova/* +.php-cs-fixer.cache diff --git a/README.md b/README.md index 19249dc..d713670 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ## Requirments -PHP >= 8.0 +PHP >= 8.1 ## Install diff --git a/component/Data/EmailServiceProvider.php b/component/Data/EmailServiceProvider.php index 0f7c6cb..2cb7068 100644 --- a/component/Data/EmailServiceProvider.php +++ b/component/Data/EmailServiceProvider.php @@ -1,67 +1,68 @@ message = 'The domain name "' . $domainName . '" has an invalid format.'; - } + public function __construct(string $domainName) + { + $this->message = 'The domain name "' . $domainName . '" has an invalid format.'; + } } diff --git a/component/Service/DnsRecord.php b/component/Service/DnsRecord.php index 857735e..0645428 100644 --- a/component/Service/DnsRecord.php +++ b/component/Service/DnsRecord.php @@ -1,4 +1,5 @@ \DNS_A, - self::CNAME => \DNS_CNAME, - self::HINFO => \DNS_HINFO, - self::CAA => \DNS_CAA, - self::MX => \DNS_MX, - self::NS => \DNS_NS, - self::PTR => \DNS_PTR, - self::SOA => \DNS_SOA, - self::TXT => \DNS_TXT, - self::AAAA => \DNS_AAAA, - self::SRV => \DNS_SRV, - self::NAPTR => \DNS_NAPTR, - self::A6 => \DNS_A6, - self::ALL => \DNS_ALL, - self::ANY => \DNS_ANY, - ]; - - public function get(string|DomainName $domainName, string $record): ?array - { - if (is_string($domainName)) $domainName = new DomainName($domainName); - - return dns_get_record((string)$domainName, self::STANDARDS[ $record ]) ?? null; - } - - public function exist(string|DomainName $domainName, string $record): bool - { - if (is_string($domainName)) $domainName = new DomainName($domainName); - - return checkdnsrr((string)$domainName, $record); - } + public const A = 'A'; + public const CNAME = 'CNAME'; + public const HINFO = 'HINFO'; + public const CAA = 'CAA'; + public const MX = 'MX'; + public const NS = 'NS'; + public const PTR = 'PTR'; + public const SOA = 'SOA'; + public const TXT = 'TXT'; + public const AAAA = 'AAAA'; + public const SRV = 'SRV'; + public const NAPTR = 'NAPTR'; + public const A6 = 'A6'; + public const ALL = 'ALL'; + public const ANY = 'ANY'; + + private const STANDARDS = [ + self::A => \DNS_A, + self::CNAME => \DNS_CNAME, + self::HINFO => \DNS_HINFO, + self::CAA => \DNS_CAA, + self::MX => \DNS_MX, + self::NS => \DNS_NS, + self::PTR => \DNS_PTR, + self::SOA => \DNS_SOA, + self::TXT => \DNS_TXT, + self::AAAA => \DNS_AAAA, + self::SRV => \DNS_SRV, + self::NAPTR => \DNS_NAPTR, + self::A6 => \DNS_A6, + self::ALL => \DNS_ALL, + self::ANY => \DNS_ANY, + ]; + + public function get(string|DomainName $domainName, string $record): ?array + { + if (is_string($domainName)) { + $domainName = new DomainName($domainName); + } + + return dns_get_record((string)$domainName, self::STANDARDS[ $record ]) ?? null; + } + + public function exist(string|DomainName $domainName, string $record): bool + { + if (is_string($domainName)) { + $domainName = new DomainName($domainName); + } + + return checkdnsrr((string)$domainName, $record); + } } diff --git a/component/Service/ServiceProvided.php b/component/Service/ServiceProvided.php index 52c9449..f5366c2 100644 --- a/component/Service/ServiceProvided.php +++ b/component/Service/ServiceProvided.php @@ -1,27 +1,32 @@ =8.1", + "phant/data-structure": "4.*" }, "require-dev": { + "friendsofphp/php-cs-fixer": "^3.0", "phpstan/phpstan": "^1.4", "phpunit/phpunit": "^9.5" }, "scripts": { + "lint": "vendor/bin/php-cs-fixer fix ./ --rules=@PSR12", "analyse": "vendor/bin/phpstan analyse component --memory-limit=4G", "test": "vendor/bin/phpunit test --testdox" }, diff --git a/test/Service/DnsRecordTest.php b/test/Service/DnsRecordTest.php index b7306c1..67b1cd9 100644 --- a/test/Service/DnsRecordTest.php +++ b/test/Service/DnsRecordTest.php @@ -1,7 +1,9 @@ assertIsArray( - (new DnsRecord()) - ->get( - 'github.com', - DnsRecord::A - ) - ); - - $this->assertIsArray( - (new DnsRecord()) - ->get( - new DomainName('github.com'), - DnsRecord::A - ) - ); - } - - public function testExist(): void - { - $this->assertIsBool( - (new DnsRecord()) - ->exist( - 'github.com', - DnsRecord::A - ) - ); - - $this->assertIsBool( - (new DnsRecord()) - ->exist( - new DomainName('github.com'), - DnsRecord::A - ) - ); - } + public function testGet(): void + { + $this->assertIsArray( + (new DnsRecord()) + ->get( + 'github.com', + DnsRecord::A + ) + ); + + $this->assertIsArray( + (new DnsRecord()) + ->get( + new DomainName('github.com'), + DnsRecord::A + ) + ); + } + + public function testExist(): void + { + $this->assertIsBool( + (new DnsRecord()) + ->exist( + 'github.com', + DnsRecord::A + ) + ); + + $this->assertIsBool( + (new DnsRecord()) + ->exist( + new DomainName('github.com'), + DnsRecord::A + ) + ); + } } diff --git a/test/Service/ServiceProvidedTest.php b/test/Service/ServiceProvidedTest.php index ec49598..74ad5c4 100644 --- a/test/Service/ServiceProvidedTest.php +++ b/test/Service/ServiceProvidedTest.php @@ -1,7 +1,9 @@ isEmailServiceProvider( - 'gmail.com' - ); - - $result = (new ServiceProvided()) - ->isEmailServiceProvider( - new DomainName('gmail.com') - ); - - $this->assertIsBool($result); - $this->assertEquals(true, $result); - } - - public function testIsEmailServiceProviderFalse(): void - { - $result = (new ServiceProvided()) - ->isEmailServiceProvider( - 'trash-mail.com' - ); - - $result = (new ServiceProvided()) - ->isEmailServiceProvider( - new DomainName('trash-mail.com') - ); - - $this->assertIsBool($result); - $this->assertEquals(false, $result); - } - - public function testIsTrashMailBoxServiceTrue(): void - { - $result = (new ServiceProvided()) - ->isTrashMailBoxService( - 'trash-mail.com' - ); - - $result = (new ServiceProvided()) - ->isTrashMailBoxService( - new DomainName('trash-mail.com') - ); - - $this->assertIsBool($result); - $this->assertEquals(true, $result); - } - - public function testIsTrashMailBoxServiceFalse(): void - { - $result = (new ServiceProvided()) - ->isTrashMailBoxService( - 'gmail.com' - ); - - $result = (new ServiceProvided()) - ->isTrashMailBoxService( - new DomainName('gmail.com') - ); - - $this->assertIsBool($result); - $this->assertEquals(false, $result); - } + public function testIsEmailServiceProviderTrue(): void + { + $result = (new ServiceProvided()) + ->isEmailServiceProvider( + 'gmail.com' + ); + + $result = (new ServiceProvided()) + ->isEmailServiceProvider( + new DomainName('gmail.com') + ); + + $this->assertIsBool($result); + $this->assertEquals(true, $result); + } + + public function testIsEmailServiceProviderFalse(): void + { + $result = (new ServiceProvided()) + ->isEmailServiceProvider( + 'trash-mail.com' + ); + + $result = (new ServiceProvided()) + ->isEmailServiceProvider( + new DomainName('trash-mail.com') + ); + + $this->assertIsBool($result); + $this->assertEquals(false, $result); + } + + public function testIsTrashMailBoxServiceTrue(): void + { + $result = (new ServiceProvided()) + ->isTrashMailBoxService( + 'trash-mail.com' + ); + + $result = (new ServiceProvided()) + ->isTrashMailBoxService( + new DomainName('trash-mail.com') + ); + + $this->assertIsBool($result); + $this->assertEquals(true, $result); + } + + public function testIsTrashMailBoxServiceFalse(): void + { + $result = (new ServiceProvided()) + ->isTrashMailBoxService( + 'gmail.com' + ); + + $result = (new ServiceProvided()) + ->isTrashMailBoxService( + new DomainName('gmail.com') + ); + + $this->assertIsBool($result); + $this->assertEquals(false, $result); + } }