Skip to content

Commit

Permalink
Merge pull request #48 from remotelyliving/upgrades
Browse files Browse the repository at this point in the history
Upgrades
  • Loading branch information
Christian Thomas authored Mar 11, 2022
2 parents fa1eebe + 7dbc6d8 commit 2cac1c4
Show file tree
Hide file tree
Showing 75 changed files with 492 additions and 979 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/php-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: ['7.4', '8.0']
php-versions: ['8.0', '8.1']
name: PHP ${{ matrix.php-versions }} Test on Ubuntu
steps:
- uses: actions/checkout@v2
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ composer.phar
/.idea/
.DS_Store
.churn.cache
composer.lock
composer.lock
.phpunit.result.cache
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ dependencies:
@composer install

unit-tests:
@vendor/bin/phpunit --bootstrap=./tests/bootstrap.php --testsuite Unit
@vendor/bin/paratest -p8 --runner=WrapperRunner --bootstrap=./tests/bootstrap.php --testsuite Unit

integration-tests:
@vendor/bin/phpunit --bootstrap=./tests/bootstrap.php --testsuite Integration
@vendor/bin/paratest -p8 --runner=WrapperRunner --bootstrap=./tests/bootstrap.php --testsuite Integration

test-coverage-ci:
@mkdir -p ./build/logs && ./vendor/bin/phpunit -c phpunit.xml.dist --coverage-clover ./build/logs/clover.xml && php vendor/bin/php-coveralls --root_dir=. -v

test-coverage-html:
@vendor/bin/phpunit --coverage-html ./coverage
@vendor/bin/paratest -p8 --runner=WrapperRunner --bootstrap=./tests/bootstrap.php --coverage-html ./coverage

style-check:
@vendor/bin/phpcs --standard=PSR12 ./src/* ./tests/*
Expand All @@ -32,4 +32,4 @@ style-fix:
@vendor/bin/phpcbf --standard=PSR12 ./src ./tests

repl:
@vendor/bin/psysh ./bootstrap/repl.php
@vendor/bin/psysh bootstrap/repl.php
4 changes: 2 additions & 2 deletions bootstrap/repl.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
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 Spatie\Dns\Dns;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;

class_alias(Hostname::class, 'Hostname');
Expand All @@ -33,7 +33,7 @@ class_alias(DNSRecordCollection::class, 'DNSRecordCollection');
$cloudFlareResolver = new CloudFlare();
$cloudFlareResolver->addSubscriber($IOSubscriber);

$digResolver = new \RemotelyLiving\PHPDNS\Resolvers\Dig(new SpatieDNS(), new Dig());
$digResolver = new \RemotelyLiving\PHPDNS\Resolvers\Dig(new Dns(), new Dig());
$digResolver->addSubscriber($IOSubscriber);

$chainResolver = new Chain($cloudFlareResolver, $googleDNSResolver, $localSystemResolver);
Expand Down
12 changes: 9 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
],
"minimum-stability": "stable",
"require": {
"php": ">=7.4",
"php": ">=8.0",
"ext-json": "*",
"ext-filter": "*",
"ext-intl": "*",
Expand All @@ -21,7 +21,7 @@
"symfony/event-dispatcher": "^6.0 || ^5.0 || ^4.0 || ^3.0",
"psr/log": "^1.0 || ^2.0 || ^3.0",
"guzzlehttp/promises": "^1.3",
"spatie/dns": "^1.5"
"spatie/dns": "^2.0"
},
"require-dev": {
"phpunit/phpunit": "^9.0",
Expand All @@ -32,7 +32,8 @@
"symfony/cache": "^4.3",
"vimeo/psalm": "^4.10",
"rector/rector": "^0.12.8",
"bmitch/churn-php": "^1.5"
"bmitch/churn-php": "^1.5",
"brianium/paratest": "^6.4"
},
"autoload": {
"psr-4": {
Expand All @@ -43,5 +44,10 @@
"psr-4": {
"RemotelyLiving\\PHPDNS\\Tests\\" : "tests/"
}
},
"config": {
"allow-plugins": {
"composer/package-versions-deprecated": true
}
}
}
3 changes: 1 addition & 2 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0"?>
<psalm
totallyTyped="false"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
Expand Down Expand Up @@ -51,7 +50,7 @@

<InvalidStringClass errorLevel="info" />
<TypeDoesNotContainType errorLevel="info" />

<RedundantCast errorLevel="suppress" />
<TooManyArguments>
<errorLevel type="suppress">
<referencedFunction name="Symfony\Component\EventDispatcher\EventDispatcherInterface::dispatch" />
Expand Down
5 changes: 4 additions & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Rector\Core\Configuration\Option;
use Rector\Php74\Rector\Property\TypedPropertyRector;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Set\ValueObject\SetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
Expand All @@ -15,7 +16,9 @@
]);

// Define what rule sets will be applied
$containerConfigurator->import(LevelSetList::UP_TO_PHP_81);
$containerConfigurator->import(LevelSetList::UP_TO_PHP_80);
$containerConfigurator->import(SetList::DEAD_CODE);
$containerConfigurator->import(SetList::CODE_QUALITY);

// get services (needed for register a single rule)
$services = $containerConfigurator->services();
Expand Down
33 changes: 9 additions & 24 deletions src/Entities/CAAData.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,12 @@
use function trim;
use function unserialize;

final class CAAData extends DataAbstract
final class CAAData extends DataAbstract implements \Stringable
{
private int $flags;

private string $tag;

private ?string $value;

public function __construct(int $flags, string $tag, string $value = null)
public function __construct(private int $flags, private string $tag, string $value = null)
{
$this->flags = $flags;
$this->tag = $tag;
$this->value = ($value)
? $this->normalizeValue($value)
: null;
Expand All @@ -32,6 +26,13 @@ public function __toString(): string
return "{$this->flags} {$this->tag} \"{$this->value}\"";
}

public function __unserialize(array $unserialized): void
{
$this->flags = $unserialized['flags'];
$this->tag = $unserialized['tag'];
$this->value = $unserialized['value'];
}

public function getFlags(): int
{
return $this->flags;
Expand All @@ -56,22 +57,6 @@ public function toArray(): array
];
}

public function serialize(): string
{
return serialize($this->toArray());
}

/**
* @param string $serialized
*/
public function unserialize($serialized): void
{
$unserialized = unserialize($serialized);
$this->flags = $unserialized['flags'];
$this->tag = $unserialized['tag'];
$this->value = $unserialized['value'];
}

private function normalizeValue(string $value): string
{
$normalized = trim(str_ireplace('"', '', $value));
Expand Down
19 changes: 3 additions & 16 deletions src/Entities/CNAMEData.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@
use function serialize;
use function unserialize;

final class CNAMEData extends DataAbstract
final class CNAMEData extends DataAbstract implements \Stringable
{
private Hostname $hostname;

public function __construct(Hostname $hostname)
public function __construct(private Hostname $hostname)
{
$this->hostname = $hostname;
}

public function __toString(): string
Expand All @@ -31,18 +28,8 @@ public function toArray(): array
];
}

public function serialize(): string
{
return serialize($this->toArray());
}

/**
* @param string $serialized
*/
public function unserialize($serialized): void
public function __unserialize(array $unserialized): void
{
/** @var array{'hostname': string} $unserialized */
$unserialized = unserialize($serialized);
$this->hostname = new Hostname($unserialized['hostname']);
}
}
55 changes: 20 additions & 35 deletions src/Entities/DNSRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,19 @@

final class DNSRecord extends EntityAbstract implements DNSRecordInterface
{
private DNSRecordType $recordType;

private Hostname $hostname;

private int $TTL;

private ?IPAddress $IPAddress;

private string $class;

private ?DataAbstract $data;
/**
* @var string
*/
private const DATA = 'data';

public function __construct(
DNSRecordType $recordType,
Hostname $hostname,
int $ttl,
IPAddress $IPAddress = null,
string $class = 'IN',
DataAbstract $data = null
private DNSRecordType $recordType,
private Hostname $hostname,
private int $TTL,
private ?IPAddress $IPAddress = null,
private string $class = 'IN',
private ?DataAbstract $data = null
) {
$this->recordType = $recordType;
$this->hostname = $hostname;
$this->TTL = $ttl;
$this->IPAddress = $IPAddress;
$this->class = $class;
$this->data = $data;
}

public static function createFromPrimitives(
Expand Down Expand Up @@ -95,6 +78,13 @@ public function getData(): ?DataAbstract
return $this->data;
}

public function setData(DataAbstract $data): self
{

$this->data = $data;
return $this;
}

public function setTTL(int $ttl): DNSRecordInterface
{
$this->TTL = $ttl;
Expand All @@ -110,11 +100,11 @@ public function toArray(): array
'class' => $this->class,
];

if ($this->IPAddress) {
if ($this->IPAddress !== null) {
$formatted['IPAddress'] = (string)$this->IPAddress;
}

if ($this->data) {
if ($this->data !== null) {
$formatted[self::DATA] = (string)$this->data;
}

Expand All @@ -129,27 +119,22 @@ public function equals(DNSRecordInterface $record): bool
&& (string)$this->IPAddress === (string)$record->getIPAddress(); // could be null
}

public function serialize(): string
public function __serialize(): array
{
return serialize($this->toArray());
return $this->toArray();
}

/**
* @param string $serialized
*/
public function unserialize($serialized): void
public function __unserialize(array $unserialized): void
{
$unserialized = unserialize($serialized);

$rawIPAddres = $unserialized['IPAddress'] ?? null;
$this->recordType = DNSRecordType::createFromString($unserialized['type']);
$this->hostname = Hostname::createFromString($unserialized['hostname']);
$this->TTL = (int) $unserialized['TTL'];
$this->IPAddress = $rawIPAddres ? IPAddress::createFromString($rawIPAddres) : null;
$this->class = $unserialized['class'];
$this->data = (isset($unserialized[self::DATA]))
? DataAbstract::createFromTypeAndString($this->recordType, $unserialized[self::DATA])
: null;
? DataAbstract::createFromTypeAndString($this->recordType, $unserialized[self::DATA])
: null;
}

public function jsonSerialize(): array
Expand Down
Loading

0 comments on commit 2cac1c4

Please sign in to comment.