1
0
mirror of https://github.com/danog/LibDNSJson.git synced 2024-11-26 11:54:47 +01:00

Switch to PHP 8.1

This commit is contained in:
Daniil Gentili 2022-12-05 22:13:49 +01:00
parent 2beef48935
commit a49d793094
13 changed files with 46 additions and 113 deletions

1
.gitignore vendored
View File

@ -5,3 +5,4 @@ phpunit.xml
vendor
.php_cs.cache
coverage
*.cache

View File

@ -3,11 +3,7 @@ sudo: false
language: php
php:
- 7.0
- 7.1
- 7.2
- 7.3
- nightly
- 8.1
matrix:
allow_failures:

View File

@ -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

View File

@ -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"
}
}
}

View File

@ -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
*/

View File

@ -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
{

View File

@ -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
{

View File

@ -26,7 +26,6 @@ class QueryEncoderFactory
/**
* Create a new Encoder object.
*
* @return \LibDNS\Encoder\Encoder
*/
public function create(): QueryEncoder
{

View File

@ -1,25 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.0/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
>
<testsuites>
<testsuite name="Main">
<directory>test</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">lib</directory>
</whitelist>
</filter>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" backupGlobals="false" backupStaticAttributes="false" bootstrap="vendor/autoload.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false">
<coverage>
<include>
<directory suffix=".php">lib</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Main">
<directory>test</directory>
</testsuite>
</testsuites>
</phpunit>

15
psalm.xml Normal file
View File

@ -0,0 +1,15 @@
<?xml version="1.0"?>
<psalm
errorLevel="2"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="lib" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
</psalm>

View File

@ -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.
*

View File

@ -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