Apply phpcs fixes

This commit is contained in:
Daniil Gentili 2019-06-11 20:07:46 +02:00
parent 755da95c12
commit e248085fda
21 changed files with 103 additions and 118 deletions

View File

@ -2,8 +2,8 @@
require __DIR__ . "/_bootstrap.php";
use Amp\DoH;
use Amp\Dns;
use Amp\DoH;
use Amp\Loop;
print "Downloading top 500 domains..." . PHP_EOL;

View File

@ -6,8 +6,6 @@ use Amp\Dns;
use Amp\DoH;
use Amp\Loop;
use Amp\Promise;
use Amp\DoH\Nameserver;
use function Amp\call;
$customConfigLoader = new class implements Dns\ConfigLoader {
public function loadConfig(): Promise
@ -36,4 +34,3 @@ Loop::run(function () {
pretty_print_error($hostname, $e);
}
});

View File

@ -4,8 +4,8 @@ require __DIR__ . "/_bootstrap.php";
use Amp\Dns;
use Amp\DoH;
use Amp\Loop;
use Amp\DoH\Nameserver;
use Amp\Loop;
// Set default resolver to DNS-over-https resolver
$DohConfig = new DoH\DoHConfig([new DoH\Nameserver('https://google.com/resolve', Nameserver::GOOGLE_JSON, ["Host" => "dns.google.com"])]);
@ -20,4 +20,3 @@ Loop::run(function () {
pretty_print_error($hostname, $e);
}
});

View File

@ -6,12 +6,12 @@ use Amp\Artax\Client;
use Amp\Artax\DefaultClient;
use Amp\Cache\ArrayCache;
use Amp\Cache\Cache;
use Amp\Dns\ConfigException;
use Amp\Dns\ConfigLoader;
use Amp\Dns\Resolver;
use Amp\Dns\Rfc1035StubResolver;
use Amp\Dns\UnixConfigLoader;
use Amp\Dns\WindowsConfigLoader;
use Amp\Dns\Rfc1035StubResolver;
use Amp\Dns\ConfigException;
final class DoHConfig
{
@ -38,7 +38,6 @@ final class DoHConfig
? new WindowsConfigLoader
: new UnixConfigLoader);
$this->subResolver = $resolver ?? new Rfc1035StubResolver(null, $this->configLoader);
}
private function validateNameserver($nameserver)
@ -58,7 +57,6 @@ final class DoHConfig
if ($nameserver->getHost() === $string) {
return true;
}
}
return false;
}

View File

@ -5,16 +5,14 @@ namespace Amp\DoH\Internal;
use Amp;
use Amp\Artax\Client;
use Amp\Artax\Request;
use Amp\Artax\Response;
use Amp\Deferred;
use Amp\DoH\JsonDecoderFactory;
use Amp\DoH\Nameserver;
use Amp\DoH\QueryEncoderFactory;
use Amp\Promise;
use function Amp\call;
use LibDNS\Decoder\DecoderFactory;
use LibDNS\Encoder\EncoderFactory;
use LibDNS\Messages\Message;
use Amp\DoH\JsonDecoderFactory;
use Amp\DoH\QueryEncoderFactory;
use function Amp\call;
/** @internal */
final class HttpsSocket extends Socket
@ -94,5 +92,4 @@ final class HttpsSocket extends Socket
}
});
}
}

View File

@ -11,11 +11,11 @@ use Amp\Dns\DnsException;
use Amp\Dns\TimeoutException;
use Amp\DoH\Nameserver;
use Amp\Promise;
use function Amp\call;
use LibDNS\Messages\Message;
use LibDNS\Messages\MessageFactory;
use LibDNS\Messages\MessageTypes;
use LibDNS\Records\Question;
use function Amp\call;
/** @internal */
abstract class Socket
@ -92,8 +92,7 @@ abstract class Socket
} while (isset($this->pending[$id]));
$deferred = new Deferred;
$pending = new class
{
$pending = new class {
use Amp\Struct;
public $deferred;

View File

@ -1,9 +1,12 @@
<?php
namespace Amp\DoH;
use Amp\Dns\DnsException;
use LibDNS\Decoder\DecodingContextFactory;
use LibDNS\Messages\Message;
use LibDNS\Messages\MessageFactory;
use LibDNS\Messages\MessageTypes;
use LibDNS\Packets\Packet;
use LibDNS\Packets\PacketFactory;
use LibDNS\Records\Question;
@ -22,11 +25,9 @@ use LibDNS\Records\Types\Short;
use LibDNS\Records\Types\Type;
use LibDNS\Records\Types\TypeBuilder;
use LibDNS\Records\Types\Types;
use LibDNS\Messages\MessageTypes;
use Amp\Dns\DnsException;
/**
* Decodes JSON DNS strings to Message objects
* Decodes JSON DNS strings to Message objects.
*
* @author Daniil Gentili <https://daniil.it>, Chris Wright <https://github.com/DaveRandom>
*/
@ -63,7 +64,7 @@ class JsonDecoder
private $decodingContextFactory;
/**
* Constructor
* Constructor.
*
* @param \LibDNS\Packets\PacketFactory $packetFactory
* @param \LibDNS\Messages\MessageFactory $messageFactory
@ -89,7 +90,7 @@ class JsonDecoder
$this->decodingContextFactory = $decodingContextFactory;
}
/**
* Decode a question record
* Decode a question record.
*
*
* @return \LibDNS\Records\Question
@ -99,8 +100,8 @@ class JsonDecoder
{
/** @var \LibDNS\Records\Types\DomainName $domainName */
$domainName = $this->typeBuilder->build(Types::DOMAIN_NAME);
$labels = explode('.', $record['name']);
if (!empty($last = array_pop($labels))) {
$labels = \explode('.', $record['name']);
if (!empty($last = \array_pop($labels))) {
$labels[] = $last;
}
$domainName->setLabels($labels);
@ -112,7 +113,7 @@ class JsonDecoder
}
/**
* Decode a resource record
* Decode a resource record.
*
*
* @return \LibDNS\Records\Resource
@ -123,8 +124,8 @@ class JsonDecoder
{
/** @var \LibDNS\Records\Types\DomainName $domainName */
$domainName = $this->typeBuilder->build(Types::DOMAIN_NAME);
$labels = explode('.', $record['name']);
if (!empty($last = array_pop($labels))) {
$labels = \explode('.', $record['name']);
if (!empty($last = \array_pop($labels))) {
$labels[] = $last;
}
$domainName->setLabels($labels);
@ -146,7 +147,7 @@ class JsonDecoder
return $resource;
}
/**
* Decode a Type field
* Decode a Type field.
*
*
* @param \LibDNS\Records\Types\Type $type The object to populate with the result
@ -178,7 +179,7 @@ class JsonDecoder
}
}
/**
* Decode an Anything field
* Decode an Anything field.
*
*
* @param \LibDNS\Records\Types\Anything $anything The object to populate with the result
@ -188,11 +189,11 @@ class JsonDecoder
*/
private function decodeAnything(Anything $anything, $data)
{
$anything->setValue(hex2bin($data));
$anything->setValue(\hex2bin($data));
}
/**
* Decode a BitMap field
* Decode a BitMap field.
*
*
* @param \LibDNS\Records\Types\BitMap $bitMap The object to populate with the result
@ -202,11 +203,11 @@ class JsonDecoder
*/
private function decodeBitMap(BitMap $bitMap, $data)
{
$bitMap->setValue(hex2bin($data));
$bitMap->setValue(\hex2bin($data));
}
/**
* Decode a Char field
* Decode a Char field.
*
*
* @param \LibDNS\Records\Types\Char $char The object to populate with the result
@ -220,7 +221,7 @@ class JsonDecoder
}
/**
* Decode a CharacterString field
* Decode a CharacterString field.
*
*
* @param \LibDNS\Records\Types\CharacterString $characterString The object to populate with the result
@ -233,7 +234,7 @@ class JsonDecoder
}
/**
* Decode a DomainName field
* Decode a DomainName field.
*
*
* @param \LibDNS\Records\Types\DomainName $domainName The object to populate with the result
@ -242,8 +243,8 @@ class JsonDecoder
*/
private function decodeDomainName(DomainName $domainName, $result)
{
$labels = explode('.', $result);
if (!empty($last = array_pop($labels))) {
$labels = \explode('.', $result);
if (!empty($last = \array_pop($labels))) {
$labels[] = $last;
}
@ -251,7 +252,7 @@ class JsonDecoder
}
/**
* Decode an IPv4Address field
* Decode an IPv4Address field.
*
*
* @param \LibDNS\Records\Types\IPv4Address $ipv4Address The object to populate with the result
@ -260,12 +261,12 @@ class JsonDecoder
*/
private function decodeIPv4Address(IPv4Address $ipv4Address, $result)
{
$octets = \unpack('C4', inet_pton($result));
$octets = \unpack('C4', \inet_pton($result));
$ipv4Address->setOctets($octets);
}
/**
* Decode an IPv6Address field
* Decode an IPv6Address field.
*
*
* @param \LibDNS\Records\Types\IPv6Address $ipv6Address The object to populate with the result
@ -274,12 +275,12 @@ class JsonDecoder
*/
private function decodeIPv6Address(IPv6Address $ipv6Address, $result)
{
$shorts = \unpack('n8', inet_pton($result));
$shorts = \unpack('n8', \inet_pton($result));
$ipv6Address->setShorts($shorts);
}
/**
* Decode a Long field
* Decode a Long field.
*
*
* @param \LibDNS\Records\Types\Long $long The object to populate with the result
@ -292,7 +293,7 @@ class JsonDecoder
}
/**
* Decode a Short field
* Decode a Short field.
*
*
* @param \LibDNS\Records\Types\Short $short The object to populate with the result
@ -305,7 +306,7 @@ class JsonDecoder
}
/**
* Decode a Message from JSON-encoded string
* Decode a Message from JSON-encoded string.
*
* @param string $data The data string to decode
* @param int $requestId The message ID to set
@ -335,10 +336,10 @@ class JsonDecoder
$message->isRecursionDesired($result['RD']);
$message->isRecursionAvailable($result['RA']);
$decodingContext->setExpectedQuestionRecords(isset($result['Question']) ? count($result['Question']) : 0);
$decodingContext->setExpectedAnswerRecords(isset($result['Answer']) ? count($result['Answer']) : 0);
$decodingContext->setExpectedQuestionRecords(isset($result['Question']) ? \count($result['Question']) : 0);
$decodingContext->setExpectedAnswerRecords(isset($result['Answer']) ? \count($result['Answer']) : 0);
$decodingContext->setExpectedAuthorityRecords(0);
$decodingContext->setExpectedAdditionalRecords(isset($result['Additional']) ? count($result['Additional']) : 0);
$decodingContext->setExpectedAdditionalRecords(isset($result['Additional']) ? \count($result['Additional']) : 0);
$questionRecords = $message->getQuestionRecords();
$expected = $decodingContext->getExpectedQuestionRecords();

View File

@ -1,37 +1,38 @@
<?php
/**
* Creates Decoder objects
* Creates Decoder objects.
*
* @author Chris Wright <https://github.com/DaveRandom>
* @copyright Copyright (c) Chris Wright <https://github.com/DaveRandom>,
* @license http://www.opensource.org/licenses/mit-license.html MIT License
*/
namespace Amp\DoH;
use \LibDNS\Packets\PacketFactory;
use \LibDNS\Messages\MessageFactory;
use \LibDNS\Records\RecordCollectionFactory;
use \LibDNS\Packets\PacketFactory;
use \LibDNS\Records\QuestionFactory;
use \LibDNS\Records\ResourceBuilder;
use \LibDNS\Records\ResourceFactory;
use \LibDNS\Records\RDataBuilder;
use \LibDNS\Records\RDataFactory;
use \LibDNS\Records\RecordCollectionFactory;
use \LibDNS\Records\ResourceBuilder;
use \LibDNS\Records\ResourceFactory;
use \LibDNS\Records\TypeDefinitions\FieldDefinitionFactory;
use \LibDNS\Records\TypeDefinitions\TypeDefinitionFactory;
use \LibDNS\Records\TypeDefinitions\TypeDefinitionManager;
use \LibDNS\Records\Types\TypeBuilder;
use \LibDNS\Records\Types\TypeFactory;
use \LibDNS\Records\TypeDefinitions\TypeDefinitionManager;
use \LibDNS\Records\TypeDefinitions\TypeDefinitionFactory;
use \LibDNS\Records\TypeDefinitions\FieldDefinitionFactory;
use LibDNS\Decoder\DecodingContextFactory;
/**
* Creates JsonDecoder objects
* Creates JsonDecoder objects.
*
* @author Chris Wright <https://github.com/DaveRandom>
*/
class JsonDecoderFactory
{
/**
* Create a new JsonDecoder object
* Create a new JsonDecoder object.
*
* @param \LibDNS\Records\TypeDefinitions\TypeDefinitionManager $typeDefinitionManager
* @return JsonDecoder

View File

@ -2,7 +2,6 @@
namespace Amp\DoH;
use Amp\Uri\InvalidDnsNameException;
use Amp\Dns\ConfigException;
final class Nameserver
@ -18,16 +17,16 @@ final class Nameserver
public function __construct(string $uri, int $type = self::RFC8484_POST, array $headers = [])
{
if (parse_url($uri, PHP_URL_SCHEME) !== 'https') {
if (\parse_url($uri, PHP_URL_SCHEME) !== 'https') {
throw new ConfigException('Did not provide a valid HTTPS url!');
}
if (!in_array($type, [self::RFC8484_GET, self::RFC8484_POST, self::GOOGLE_JSON])) {
if (!\in_array($type, [self::RFC8484_GET, self::RFC8484_POST, self::GOOGLE_JSON])) {
throw new ConfigException('Invalid nameserver type provided!');
}
$this->uri = $uri;
$this->type = $type;
$this->headers = $headers;
$this->host = parse_url($uri, PHP_URL_HOST);
$this->host = \parse_url($uri, PHP_URL_HOST);
}
public function getUri(): string
{

View File

@ -1,6 +1,6 @@
<?php declare(strict_types = 1);
/**
* Encodes Message objects to raw network data
* Encodes Message objects to raw network data.
*
* PHP version 5.4
*
@ -11,14 +11,15 @@
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 2.0.0
*/
namespace Amp\DoH;
use Amp\Dns\DnsException;
use \LibDNS\Messages\Message;
use Amp\Dns\DnsException;
use LibDNS\Messages\MessageTypes;
/**
* Encodes Message objects to raw network data
* Encodes Message objects to raw network data.
*
* @category LibDNS
* @package Encoder
@ -27,7 +28,7 @@ use LibDNS\Messages\MessageTypes;
class QueryEncoder
{
/**
* Encode a Message to URL payload
* Encode a Message to URL payload.
*
* @param \LibDNS\Messages\Message $message The Message to encode
* @return string
@ -47,7 +48,7 @@ class QueryEncoder
'cd' => 0, // Do not disable result validation
'do' => 0, // Do not send me DNSSEC data
'type' => $question->getType(), // Record type being requested
'name' => implode('.', $question->getName()->getLabels()), // Record name being requested
'name' => \implode('.', $question->getName()->getLabels()), // Record name being requested
'ct' => 'application/dns-json', // Content-type of request
]
);

View File

@ -1,6 +1,6 @@
<?php declare(strict_types=1);
/**
* Creates Encoder objects
* Creates Encoder objects.
*
* PHP version 5.4
*
@ -11,12 +11,11 @@
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 2.0.0
*/
namespace Amp\DoH;
use \LibDNS\Packets\PacketFactory;
/**
* Creates Encoder objects
* Creates Encoder objects.
*
* @category LibDNS
* @package Encoder
@ -25,7 +24,7 @@ use \LibDNS\Packets\PacketFactory;
class QueryEncoderFactory
{
/**
* Create a new Encoder object
* Create a new Encoder object.
*
* @return \LibDNS\Encoder\Encoder
*/

View File

@ -3,23 +3,21 @@
namespace Amp\DoH;
use Amp\Cache\Cache;
use Amp\Dns\ConfigLoader;
use Amp\Dns\ConfigException;
use Amp\Dns\DnsException;
use Amp\Dns\NoRecordException;
use Amp\Dns\Record;
use Amp\Dns\Resolver;
use Amp\Dns\Rfc1035StubResolver;
use Amp\Dns\TimeoutException;
use Amp\DoH\Internal\HttpsSocket;
use Amp\DoH\Internal\Socket;
use Amp\MultiReasonException;
use Amp\Promise;
use function Amp\call;
use function Amp\Dns\normalizeName;
use LibDNS\Messages\Message;
use LibDNS\Records\Question;
use LibDNS\Records\QuestionFactory;
use Amp\Dns\ConfigException;
use function Amp\call;
use function Amp\Dns\normalizeName;
final class Rfc8484StubResolver implements Resolver
{

View File

@ -4,14 +4,12 @@ namespace Amp\DoH\Test;
use Amp\Artax\DefaultClient;
use Amp\Cache\ArrayCache;
use Amp\Dns\Config;
use Amp\Dns\ConfigException;
use Amp\Dns\Rfc1035StubResolver;
use Amp\Dns\UnixConfigLoader;
use Amp\Dns\WindowsConfigLoader;
use Amp\DoH\DoHConfig;
use Amp\DoH\Nameserver;
use Amp\DoH\Rfc8484StubResolver;
use Amp\PHPUnit\TestCase;
class DoHConfigTest extends TestCase

View File

@ -3,12 +3,12 @@
namespace Amp\DoH\Test;
use Amp\Artax\DefaultClient;
use Amp\DoH;
use Amp\Dns;
use Amp\DoH\Nameserver;
use function Amp\Promise\wait;
use LibDNS\Records\QuestionFactory;
use Amp\DoH;
use Amp\DoH\Internal\Socket;
use Amp\DoH\Nameserver;
use LibDNS\Records\QuestionFactory;
use function Amp\Promise\wait;
class HttpsSocketTest extends SocketTest
{

View File

@ -2,9 +2,9 @@
namespace Amp\DoH\Test;
use Amp\PHPUnit\TestCase;
use Amp\DoH\JsonDecoderFactory;
use Amp\DoH\JsonDecoder;
use Amp\DoH\JsonDecoderFactory;
use Amp\PHPUnit\TestCase;
class JsonDecoderFactoryTest extends TestCase
{

View File

@ -2,16 +2,16 @@
namespace Amp\DoH\Test;
use Amp\Dns\DnsException;
use Amp\DoH\JsonDecoderFactory;
use Amp\PHPUnit\TestCase;
use LibDNS\Messages\Message;
use Amp\Dns\DnsException;
use LibDNS\Messages\MessageTypes;
class JsonDecoderTest extends TestCase
{
/**
* Test decoding of valid JSON DNS payloads
* Test decoding of valid JSON DNS payloads.
*
* @param string $message
* @param int $requestId
@ -89,7 +89,7 @@ class JsonDecoderTest extends TestCase
/**
* Test decoding of invalid JSON DNS payloads
* Test decoding of invalid JSON DNS payloads.
*
* @param string $message
* @param int $requestId

View File

@ -2,9 +2,9 @@
namespace Amp\DoH\Test;
use Amp\PHPUnit\TestCase;
use Amp\DoH\Nameserver;
use Amp\Dns\ConfigException;
use Amp\DoH\Nameserver;
use Amp\PHPUnit\TestCase;
class NameserverTest extends TestCase
{
@ -74,5 +74,4 @@ class NameserverTest extends TestCase
['https://mozilla.cloudflare-dns.com/dns-query', -1],
];
}
}

View File

@ -2,9 +2,9 @@
namespace Amp\DoH\Test;
use Amp\PHPUnit\TestCase;
use Amp\DoH\QueryEncoderFactory;
use Amp\DoH\QueryEncoder;
use Amp\DoH\QueryEncoderFactory;
use Amp\PHPUnit\TestCase;
class QueryEncoderFactoryTest extends TestCase
{

View File

@ -12,7 +12,7 @@ use LibDNS\Messages\MessageTypes;
class QueryEncoderTest extends TestCase
{
/**
* Test encoding of valid DNS message payloads
* Test encoding of valid DNS message payloads.
*
* @param string $message
* @return void
@ -28,8 +28,8 @@ class QueryEncoderTest extends TestCase
$encoder = (new QueryEncoderFactory)->create();
$request = $encoder->encode($response);
$this->assertInternalType('string', $request, "Got a ".gettype($request)." instead of a string");
parse_str($request, $output);
$this->assertInternalType('string', $request, "Got a ".\gettype($request)." instead of a string");
\parse_str($request, $output);
$this->assertNotEmpty($output);
$this->assertArrayHasKey('cd', $output);
$this->assertArrayHasKey('do', $output);
@ -40,7 +40,7 @@ class QueryEncoderTest extends TestCase
$this->assertEquals($output['do'], 0);
$this->assertEquals($output['ct'], 'application/dns-json');
$this->assertEquals($output['type'], $response->getQuestionRecords()->getRecordByIndex(0)->getType());
$this->assertEquals($output['name'], implode('.', $response->getQuestionRecords()->getRecordByIndex(0)->getName()->getLabels()));
$this->assertEquals($output['name'], \implode('.', $response->getQuestionRecords()->getRecordByIndex(0)->getName()->getLabels()));
}
public function provideValidQueryPayloads()
@ -103,7 +103,7 @@ class QueryEncoderTest extends TestCase
}
/**
* Test query encoding of invalid DNS payloads
* Test query encoding of invalid DNS payloads.
*
* @param $request
* @return void

View File

@ -2,15 +2,15 @@
namespace Amp\DoH\Test;
use Amp\Dns\ConfigException;
use Amp\Dns\DnsException;
use Amp\Dns\InvalidNameException;
use Amp\Dns\Record;
use Amp\Dns\Rfc1035StubResolver;
use Amp\DoH;
use Amp\DoH\Rfc8484StubResolver;
use Amp\Loop;
use Amp\PHPUnit\TestCase;
use Amp\Dns\Rfc1035StubResolver;
use Amp\Dns\ConfigException;
class Rfc8484StubResolverTest extends TestCase
{

View File

@ -3,14 +3,13 @@
namespace Amp\DoH\Test;
use Amp\Dns;
use Amp\DoH\Internal\Socket;
use Amp\DoH\Nameserver;
use Amp\Loop;
use Amp\PHPUnit\TestCase;
use Amp\Promise;
use LibDNS\Messages\Message;
use LibDNS\Messages\MessageTypes;
use LibDNS\Records\QuestionFactory;
use Amp\DoH\Internal\Socket;
use Amp\DoH\Nameserver;
abstract class SocketTest extends TestCase
{