diff --git a/.gitignore b/.gitignore index bef310b..b8583e7 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ phpunit.xml vendor .php_cs.cache coverage +*.cache diff --git a/.php_cs.dist b/.php-cs-fixer.dist.php similarity index 100% rename from .php_cs.dist rename to .php-cs-fixer.dist.php diff --git a/.travis.yml b/.travis.yml index ae930a6..a3723d7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,11 +3,7 @@ sudo: false language: php php: - - 7.0 - - 7.1 - - 7.2 - - 7.3 - - nightly + - 8.1 matrix: allow_failures: diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index 9e38621..0000000 --- a/appveyor.yml +++ /dev/null @@ -1,38 +0,0 @@ -build: false -shallow_clone: false - -platform: - - x86 - - x64 - -clone_folder: c:\projects\libdns - -cache: - - c:\tools\php73 -> appveyor.yml - -init: - - SET PATH=C:\Program Files\OpenSSL;c:\tools\php73;%PATH% - - SET COMPOSER_NO_INTERACTION=1 - - SET PHP=1 - - SET ANSICON=121x90 (121x90) - -install: - - IF EXIST c:\tools\php73 (SET PHP=0) - - IF %PHP%==1 sc config wuauserv start= auto - - IF %PHP%==1 net start wuauserv - - IF %PHP%==1 cinst -y OpenSSL.Light - - IF %PHP%==1 cinst -y php - - cd c:\tools\php73 - - IF %PHP%==1 copy php.ini-production php.ini /Y - - IF %PHP%==1 echo date.timezone="UTC" >> php.ini - - IF %PHP%==1 echo extension_dir=ext >> php.ini - - IF %PHP%==1 echo extension=php_openssl.dll >> php.ini - - IF %PHP%==1 echo extension=php_mbstring.dll >> php.ini - - IF %PHP%==1 echo extension=php_fileinfo.dll >> php.ini - - cd c:\projects\libdns - - appveyor DownloadFile https://getcomposer.org/composer.phar - - php composer.phar install --prefer-dist --no-progress - -test_script: - - cd c:\projects\libdns - - vendor/bin/phpunit --colors=always diff --git a/composer.json b/composer.json index 3611542..3223258 100644 --- a/composer.json +++ b/composer.json @@ -22,13 +22,14 @@ } ], "require": { - "php": ">=7.0", + "php": ">=8.1", "daverandom/libdns": "^2.0.1", "ext-json": "*" }, "require-dev": { - "amphp/php-cs-fixer-config": "dev-master", - "phpunit/phpunit": "^6" + "amphp/php-cs-fixer-config": "v2.x-dev", + "phpunit/phpunit": "^9", + "psalm/phar": "^5.1" }, "autoload": { "psr-4": { @@ -49,4 +50,4 @@ "cs-fix": "PHP_CS_FIXER_IGNORE_ENV=1 php-cs-fixer fix -v --diff", "test": "@php -dzend.assertions=1 -dassert.exception=1 ./vendor/bin/phpunit --coverage-text" } -} \ No newline at end of file +} diff --git a/lib/JsonDecoder.php b/lib/JsonDecoder.php index 87991b5..5793014 100644 --- a/lib/JsonDecoder.php +++ b/lib/JsonDecoder.php @@ -64,13 +64,6 @@ class JsonDecoder /** * Constructor. * - * @param \LibDNS\Packets\PacketFactory $packetFactory - * @param \LibDNS\Messages\MessageFactory $messageFactory - * @param \LibDNS\Records\QuestionFactory $questionFactory - * @param \LibDNS\Records\ResourceBuilder $resourceBuilder - * @param \LibDNS\Records\Types\TypeBuilder $typeBuilder - * @param \LibDNS\Decoder\DecodingContextFactory $decodingContextFactory - * @param bool $allowTrailingData */ public function __construct( PacketFactory $packetFactory, @@ -91,7 +84,6 @@ class JsonDecoder * Decode a question record. * * - * @return \LibDNS\Records\Question * @throws \UnexpectedValueException When the record is invalid */ private function decodeQuestionRecord(array $record): Question @@ -114,7 +106,6 @@ class JsonDecoder * Decode a resource record. * * - * @return \LibDNS\Records\Resource * @throws \UnexpectedValueException When the record is invalid * @throws \InvalidArgumentException When a type subtype is unknown */ @@ -155,7 +146,7 @@ class JsonDecoder * @throws \UnexpectedValueException When the packet data is invalid * @throws \InvalidArgumentException When the Type subtype is unknown */ - private function decodeType(Type $type, $data) + private function decodeType(Type $type, string $data): void { if ($type instanceof Anything) { $this->decodeAnything($type, $data); @@ -184,11 +175,9 @@ class JsonDecoder * * * @param \LibDNS\Records\Types\Anything $anything The object to populate with the result - * @param int $length - * @return int The number of packet bytes consumed by the operation * @throws \UnexpectedValueException When the packet data is invalid */ - private function decodeAnything(Anything $anything, $data) + private function decodeAnything(Anything $anything, string $data): void { $anything->setValue(\hex2bin($data)); } @@ -198,11 +187,9 @@ class JsonDecoder * * * @param \LibDNS\Records\Types\BitMap $bitMap The object to populate with the result - * @param int $length - * @return int The number of packet bytes consumed by the operation * @throws \UnexpectedValueException When the packet data is invalid */ - private function decodeBitMap(BitMap $bitMap, $data) + private function decodeBitMap(BitMap $bitMap, string $data): void { $bitMap->setValue(\hex2bin($data)); } @@ -212,10 +199,9 @@ class JsonDecoder * * * @param \LibDNS\Records\Types\Char $char The object to populate with the result - * @return int The number of packet bytes consumed by the operation * @throws \UnexpectedValueException When the packet data is invalid */ - private function decodeChar(Char $char, $result) + private function decodeChar(Char $char, string $result): void { $value = \unpack('C', $result)[1]; $char->setValue($value); @@ -226,10 +212,9 @@ class JsonDecoder * * * @param \LibDNS\Records\Types\CharacterString $characterString The object to populate with the result - * @return int The number of packet bytes consumed by the operation * @throws \UnexpectedValueException When the packet data is invalid */ - private function decodeCharacterString(CharacterString $characterString, $result) + private function decodeCharacterString(CharacterString $characterString, string $result): void { $characterString->setValue($result); } @@ -239,10 +224,9 @@ class JsonDecoder * * * @param \LibDNS\Records\Types\DomainName $domainName The object to populate with the result - * @return int The number of packet bytes consumed by the operation * @throws \UnexpectedValueException When the packet data is invalid */ - private function decodeDomainName(DomainName $domainName, $result) + private function decodeDomainName(DomainName $domainName, string $result): void { $labels = \explode('.', $result); if (!empty($last = \array_pop($labels))) { @@ -257,10 +241,9 @@ class JsonDecoder * * * @param \LibDNS\Records\Types\IPv4Address $ipv4Address The object to populate with the result - * @return int The number of packet bytes consumed by the operation * @throws \UnexpectedValueException When the packet data is invalid */ - private function decodeIPv4Address(IPv4Address $ipv4Address, $result) + private function decodeIPv4Address(IPv4Address $ipv4Address, string $result): void { $octets = \unpack('C4', \inet_pton($result)); $ipv4Address->setOctets($octets); @@ -271,10 +254,9 @@ class JsonDecoder * * * @param \LibDNS\Records\Types\IPv6Address $ipv6Address The object to populate with the result - * @return int The number of packet bytes consumed by the operation * @throws \UnexpectedValueException When the packet data is invalid */ - private function decodeIPv6Address(IPv6Address $ipv6Address, $result) + private function decodeIPv6Address(IPv6Address $ipv6Address, string $result): void { $shorts = \unpack('n8', \inet_pton($result)); $ipv6Address->setShorts($shorts); @@ -285,12 +267,11 @@ class JsonDecoder * * * @param \LibDNS\Records\Types\Long $long The object to populate with the result - * @return int The number of packet bytes consumed by the operation * @throws \UnexpectedValueException When the packet data is invalid */ - private function decodeLong(Long $long, $result) + private function decodeLong(Long $long, string $result): void { - $long->setValue((int) $result); + $long->setValue($result); } /** @@ -298,20 +279,17 @@ class JsonDecoder * * * @param \LibDNS\Records\Types\Short $short The object to populate with the result - * @return int The number of packet bytes consumed by the operation * @throws \UnexpectedValueException When the packet data is invalid */ - private function decodeShort(Short $short, $result) + private function decodeShort(Short $short, string $result): void { - $short->setValue((int) $result); + $short->setValue($result); } /** * Decode a Message from JSON-encoded string. * - * @param string $data The data string to decode * @param int $requestId The message ID to set - * @return \LibDNS\Messages\Message * @throws \UnexpectedValueException When the packet data is invalid * @throws \InvalidArgumentException When a type subtype is unknown */ diff --git a/lib/JsonDecoderFactory.php b/lib/JsonDecoderFactory.php index 0eab3e6..80bd2db 100644 --- a/lib/JsonDecoderFactory.php +++ b/lib/JsonDecoderFactory.php @@ -35,7 +35,6 @@ class JsonDecoderFactory * Create a new JsonDecoder object. * * @param \LibDNS\Records\TypeDefinitions\TypeDefinitionManager $typeDefinitionManager - * @return JsonDecoder */ public function create(TypeDefinitionManager $typeDefinitionManager = null): JsonDecoder { diff --git a/lib/QueryEncoder.php b/lib/QueryEncoder.php index 0cb8e4e..3cea77c 100644 --- a/lib/QueryEncoder.php +++ b/lib/QueryEncoder.php @@ -30,7 +30,6 @@ class QueryEncoder * Encode a Message to URL payload. * * @param \LibDNS\Messages\Message $message The Message to encode - * @return string */ public function encode(Message $message): string { diff --git a/lib/QueryEncoderFactory.php b/lib/QueryEncoderFactory.php index c0cae05..6b4e60f 100644 --- a/lib/QueryEncoderFactory.php +++ b/lib/QueryEncoderFactory.php @@ -26,7 +26,6 @@ class QueryEncoderFactory /** * Create a new Encoder object. * - * @return \LibDNS\Encoder\Encoder */ public function create(): QueryEncoder { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 4b81b12..f4c412b 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,25 +1,13 @@ - - - - test - - - - - lib - - + + + + lib + + + + + test + + diff --git a/psalm.xml b/psalm.xml new file mode 100644 index 0000000..d6746fa --- /dev/null +++ b/psalm.xml @@ -0,0 +1,15 @@ + + + + + + + + + diff --git a/test/JsonDecoderTest.php b/test/JsonDecoderTest.php index 92a7830..93c2ae1 100644 --- a/test/JsonDecoderTest.php +++ b/test/JsonDecoderTest.php @@ -12,8 +12,6 @@ class JsonDecoderTest extends TestCase /** * Test decoding of valid JSON DNS payloads. * - * @param string $message - * @param int $requestId * @return void * * @dataProvider provideValidJsonPayloads @@ -90,7 +88,6 @@ class JsonDecoderTest extends TestCase ]; } - /** * Test decoding of invalid JSON DNS payloads. * diff --git a/test/QueryEncoderTest.php b/test/QueryEncoderTest.php index 3cdf096..d85f742 100644 --- a/test/QueryEncoderTest.php +++ b/test/QueryEncoderTest.php @@ -12,7 +12,6 @@ class QueryEncoderTest extends TestCase /** * Test encoding of valid DNS message payloads. * - * @param string $message * @return void * * @dataProvider provideValidQueryPayloads @@ -26,7 +25,7 @@ class QueryEncoderTest extends TestCase $encoder = (new QueryEncoderFactory)->create(); $request = $encoder->encode($response); - $this->assertInternalType('string', $request, "Got a ".\gettype($request)." instead of a string"); + $this->assertIsString($request, "Got a ".\gettype($request)." instead of a string"); \parse_str($request, $output); $this->assertNotEmpty($output); $this->assertArrayHasKey('cd', $output); @@ -103,7 +102,6 @@ class QueryEncoderTest extends TestCase /** * Test query encoding of invalid DNS payloads. * - * @param $request * @return void * * @dataProvider provideInvalidQueryPayloads