Skip to content

Commit 2cac1c4

Browse files
author
Christian Thomas
authored
Merge pull request #48 from remotelyliving/upgrades
Upgrades
2 parents fa1eebe + 7dbc6d8 commit 2cac1c4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+492
-979
lines changed

.github/workflows/php-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ubuntu-latest
1212
strategy:
1313
matrix:
14-
php-versions: ['7.4', '8.0']
14+
php-versions: ['8.0', '8.1']
1515
name: PHP ${{ matrix.php-versions }} Test on Ubuntu
1616
steps:
1717
- uses: actions/checkout@v2

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ composer.phar
44
/.idea/
55
.DS_Store
66
.churn.cache
7-
composer.lock
7+
composer.lock
8+
.phpunit.result.cache

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ dependencies:
55
@composer install
66

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

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

1313
test-coverage-ci:
1414
@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
1515

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

1919
style-check:
2020
@vendor/bin/phpcs --standard=PSR12 ./src/* ./tests/*
@@ -32,4 +32,4 @@ style-fix:
3232
@vendor/bin/phpcbf --standard=PSR12 ./src ./tests
3333

3434
repl:
35-
@vendor/bin/psysh ./bootstrap/repl.php
35+
@vendor/bin/psysh bootstrap/repl.php

bootstrap/repl.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
use RemotelyLiving\PHPDNS\Entities\DNSRecord;
66
use RemotelyLiving\PHPDNS\Entities\DNSRecordType;
77
use RemotelyLiving\PHPDNS\Entities\DNSRecordCollection;
8-
use RemotelyLiving\PHPDNS\Factories\SpatieDNS;
98
use RemotelyLiving\PHPDNS\Mappers\Dig;
109
use RemotelyLiving\PHPDNS\Observability\Subscribers\STDIOSubscriber;
1110
use RemotelyLiving\PHPDNS\Resolvers\Cached;
1211
use RemotelyLiving\PHPDNS\Resolvers\Chain;
1312
use RemotelyLiving\PHPDNS\Resolvers\CloudFlare;
1413
use RemotelyLiving\PHPDNS\Resolvers\GoogleDNS;
1514
use RemotelyLiving\PHPDNS\Resolvers\LocalSystem;
15+
use Spatie\Dns\Dns;
1616
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
1717

1818
class_alias(Hostname::class, 'Hostname');
@@ -33,7 +33,7 @@ class_alias(DNSRecordCollection::class, 'DNSRecordCollection');
3333
$cloudFlareResolver = new CloudFlare();
3434
$cloudFlareResolver->addSubscriber($IOSubscriber);
3535

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

3939
$chainResolver = new Chain($cloudFlareResolver, $googleDNSResolver, $localSystemResolver);

composer.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
],
1212
"minimum-stability": "stable",
1313
"require": {
14-
"php": ">=7.4",
14+
"php": ">=8.0",
1515
"ext-json": "*",
1616
"ext-filter": "*",
1717
"ext-intl": "*",
@@ -21,7 +21,7 @@
2121
"symfony/event-dispatcher": "^6.0 || ^5.0 || ^4.0 || ^3.0",
2222
"psr/log": "^1.0 || ^2.0 || ^3.0",
2323
"guzzlehttp/promises": "^1.3",
24-
"spatie/dns": "^1.5"
24+
"spatie/dns": "^2.0"
2525
},
2626
"require-dev": {
2727
"phpunit/phpunit": "^9.0",
@@ -32,7 +32,8 @@
3232
"symfony/cache": "^4.3",
3333
"vimeo/psalm": "^4.10",
3434
"rector/rector": "^0.12.8",
35-
"bmitch/churn-php": "^1.5"
35+
"bmitch/churn-php": "^1.5",
36+
"brianium/paratest": "^6.4"
3637
},
3738
"autoload": {
3839
"psr-4": {
@@ -43,5 +44,10 @@
4344
"psr-4": {
4445
"RemotelyLiving\\PHPDNS\\Tests\\" : "tests/"
4546
}
47+
},
48+
"config": {
49+
"allow-plugins": {
50+
"composer/package-versions-deprecated": true
51+
}
4652
}
4753
}

psalm.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?xml version="1.0"?>
22
<psalm
3-
totallyTyped="false"
43
resolveFromConfigFile="true"
54
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
65
xmlns="https://getpsalm.org/schema/config"
@@ -51,7 +50,7 @@
5150

5251
<InvalidStringClass errorLevel="info" />
5352
<TypeDoesNotContainType errorLevel="info" />
54-
53+
<RedundantCast errorLevel="suppress" />
5554
<TooManyArguments>
5655
<errorLevel type="suppress">
5756
<referencedFunction name="Symfony\Component\EventDispatcher\EventDispatcherInterface::dispatch" />

rector.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Rector\Core\Configuration\Option;
66
use Rector\Php74\Rector\Property\TypedPropertyRector;
77
use Rector\Set\ValueObject\LevelSetList;
8+
use Rector\Set\ValueObject\SetList;
89
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
910

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

1718
// Define what rule sets will be applied
18-
$containerConfigurator->import(LevelSetList::UP_TO_PHP_81);
19+
$containerConfigurator->import(LevelSetList::UP_TO_PHP_80);
20+
$containerConfigurator->import(SetList::DEAD_CODE);
21+
$containerConfigurator->import(SetList::CODE_QUALITY);
1922

2023
// get services (needed for register a single rule)
2124
$services = $containerConfigurator->services();

src/Entities/CAAData.php

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,12 @@
1010
use function trim;
1111
use function unserialize;
1212

13-
final class CAAData extends DataAbstract
13+
final class CAAData extends DataAbstract implements \Stringable
1414
{
15-
private int $flags;
16-
17-
private string $tag;
18-
1915
private ?string $value;
2016

21-
public function __construct(int $flags, string $tag, string $value = null)
17+
public function __construct(private int $flags, private string $tag, string $value = null)
2218
{
23-
$this->flags = $flags;
24-
$this->tag = $tag;
2519
$this->value = ($value)
2620
? $this->normalizeValue($value)
2721
: null;
@@ -32,6 +26,13 @@ public function __toString(): string
3226
return "{$this->flags} {$this->tag} \"{$this->value}\"";
3327
}
3428

29+
public function __unserialize(array $unserialized): void
30+
{
31+
$this->flags = $unserialized['flags'];
32+
$this->tag = $unserialized['tag'];
33+
$this->value = $unserialized['value'];
34+
}
35+
3536
public function getFlags(): int
3637
{
3738
return $this->flags;
@@ -56,22 +57,6 @@ public function toArray(): array
5657
];
5758
}
5859

59-
public function serialize(): string
60-
{
61-
return serialize($this->toArray());
62-
}
63-
64-
/**
65-
* @param string $serialized
66-
*/
67-
public function unserialize($serialized): void
68-
{
69-
$unserialized = unserialize($serialized);
70-
$this->flags = $unserialized['flags'];
71-
$this->tag = $unserialized['tag'];
72-
$this->value = $unserialized['value'];
73-
}
74-
7560
private function normalizeValue(string $value): string
7661
{
7762
$normalized = trim(str_ireplace('"', '', $value));

src/Entities/CNAMEData.php

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,10 @@
55
use function serialize;
66
use function unserialize;
77

8-
final class CNAMEData extends DataAbstract
8+
final class CNAMEData extends DataAbstract implements \Stringable
99
{
10-
private Hostname $hostname;
11-
12-
public function __construct(Hostname $hostname)
10+
public function __construct(private Hostname $hostname)
1311
{
14-
$this->hostname = $hostname;
1512
}
1613

1714
public function __toString(): string
@@ -31,18 +28,8 @@ public function toArray(): array
3128
];
3229
}
3330

34-
public function serialize(): string
35-
{
36-
return serialize($this->toArray());
37-
}
38-
39-
/**
40-
* @param string $serialized
41-
*/
42-
public function unserialize($serialized): void
31+
public function __unserialize(array $unserialized): void
4332
{
44-
/** @var array{'hostname': string} $unserialized */
45-
$unserialized = unserialize($serialized);
4633
$this->hostname = new Hostname($unserialized['hostname']);
4734
}
4835
}

src/Entities/DNSRecord.php

Lines changed: 20 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,19 @@
99

1010
final class DNSRecord extends EntityAbstract implements DNSRecordInterface
1111
{
12-
private DNSRecordType $recordType;
13-
14-
private Hostname $hostname;
15-
16-
private int $TTL;
17-
18-
private ?IPAddress $IPAddress;
19-
20-
private string $class;
21-
22-
private ?DataAbstract $data;
2312
/**
2413
* @var string
2514
*/
2615
private const DATA = 'data';
2716

2817
public function __construct(
29-
DNSRecordType $recordType,
30-
Hostname $hostname,
31-
int $ttl,
32-
IPAddress $IPAddress = null,
33-
string $class = 'IN',
34-
DataAbstract $data = null
18+
private DNSRecordType $recordType,
19+
private Hostname $hostname,
20+
private int $TTL,
21+
private ?IPAddress $IPAddress = null,
22+
private string $class = 'IN',
23+
private ?DataAbstract $data = null
3524
) {
36-
$this->recordType = $recordType;
37-
$this->hostname = $hostname;
38-
$this->TTL = $ttl;
39-
$this->IPAddress = $IPAddress;
40-
$this->class = $class;
41-
$this->data = $data;
4225
}
4326

4427
public static function createFromPrimitives(
@@ -95,6 +78,13 @@ public function getData(): ?DataAbstract
9578
return $this->data;
9679
}
9780

81+
public function setData(DataAbstract $data): self
82+
{
83+
84+
$this->data = $data;
85+
return $this;
86+
}
87+
9888
public function setTTL(int $ttl): DNSRecordInterface
9989
{
10090
$this->TTL = $ttl;
@@ -110,11 +100,11 @@ public function toArray(): array
110100
'class' => $this->class,
111101
];
112102

113-
if ($this->IPAddress) {
103+
if ($this->IPAddress !== null) {
114104
$formatted['IPAddress'] = (string)$this->IPAddress;
115105
}
116106

117-
if ($this->data) {
107+
if ($this->data !== null) {
118108
$formatted[self::DATA] = (string)$this->data;
119109
}
120110

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

132-
public function serialize(): string
122+
public function __serialize(): array
133123
{
134-
return serialize($this->toArray());
124+
return $this->toArray();
135125
}
136126

137-
/**
138-
* @param string $serialized
139-
*/
140-
public function unserialize($serialized): void
127+
public function __unserialize(array $unserialized): void
141128
{
142-
$unserialized = unserialize($serialized);
143-
144129
$rawIPAddres = $unserialized['IPAddress'] ?? null;
145130
$this->recordType = DNSRecordType::createFromString($unserialized['type']);
146131
$this->hostname = Hostname::createFromString($unserialized['hostname']);
147132
$this->TTL = (int) $unserialized['TTL'];
148133
$this->IPAddress = $rawIPAddres ? IPAddress::createFromString($rawIPAddres) : null;
149134
$this->class = $unserialized['class'];
150135
$this->data = (isset($unserialized[self::DATA]))
151-
? DataAbstract::createFromTypeAndString($this->recordType, $unserialized[self::DATA])
152-
: null;
136+
? DataAbstract::createFromTypeAndString($this->recordType, $unserialized[self::DATA])
137+
: null;
153138
}
154139

155140
public function jsonSerialize(): array

0 commit comments

Comments
 (0)