Skip to content

Commit 10b37e0

Browse files
committed
Update PHP language syntax and remove legacy workarounds
1 parent a6cc6bb commit 10b37e0

36 files changed

+301
-323
lines changed

examples/01-one.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
$factory = new Factory();
1414
$resolver = $factory->create($config);
1515

16-
$name = isset($argv[1]) ? $argv[1] : 'www.google.com';
16+
$name = $argv[1] ?? 'www.google.com';
1717

1818
$resolver->resolve($name)->then(function ($ip) use ($name) {
1919
echo 'IP for ' . $name . ': ' . $ip . PHP_EOL;

examples/02-concurrent.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
$names = array_slice($argv, 1);
1717
if (!$names) {
18-
$names = array('google.com', 'www.google.com', 'gmail.com');
18+
$names = ['google.com', 'www.google.com', 'gmail.com'];
1919
}
2020

2121
foreach ($names as $name) {

examples/03-cached.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
$factory = new Factory();
1515
$resolver = $factory->createCached($config);
1616

17-
$name = isset($argv[1]) ? $argv[1] : 'www.google.com';
17+
$name = $argv[1] ?? 'www.google.com';
1818

1919
$resolver->resolve($name)->then(function ($ip) use ($name) {
2020
echo 'IP for ' . $name . ': ' . $ip . PHP_EOL;

examples/11-all-ips.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
$factory = new Factory();
1515
$resolver = $factory->create($config);
1616

17-
$name = isset($argv[1]) ? $argv[1] : 'www.google.com';
17+
$name = $argv[1] ?? 'www.google.com';
1818

1919
$resolver->resolveAll($name, Message::TYPE_A)->then(function (array $ips) use ($name) {
2020
echo 'IPv4 addresses for ' . $name . ': ' . implode(', ', $ips) . PHP_EOL;

examples/12-all-types.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
$factory = new Factory();
1717
$resolver = $factory->create($config);
1818

19-
$name = isset($argv[1]) ? $argv[1] : 'google.com';
20-
$type = constant('React\Dns\Model\Message::TYPE_' . (isset($argv[2]) ? $argv[2] : 'TXT'));
19+
$name = $argv[1] ?? 'google.com';
20+
$type = constant('React\Dns\Model\Message::TYPE_' . ($argv[2] ?? 'TXT'));
2121

2222
$resolver->resolveAll($name, $type)->then(function (array $values) {
2323
var_dump($values);

examples/13-reverse-dns.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
$factory = new Factory();
1515
$resolver = $factory->create($config);
1616

17-
$ip = isset($argv[1]) ? $argv[1] : '8.8.8.8';
17+
$ip = $argv[1] ?? '8.8.8.8';
1818

1919
if (@inet_pton($ip) === false) {
2020
exit('Error: Given argument is not a valid IP' . PHP_EOL);

examples/91-query-a-and-aaaa.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
$executor = new UdpTransportExecutor('8.8.8.8:53');
1111

12-
$name = isset($argv[1]) ? $argv[1] : 'www.google.com';
12+
$name = $argv[1] ?? 'www.google.com';
1313

1414
$ipv4Query = new Query($name, Message::TYPE_A, Message::CLASS_IN);
1515
$ipv6Query = new Query($name, Message::TYPE_AAAA, Message::CLASS_IN);

examples/92-query-any.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
$executor = new TcpTransportExecutor('8.8.8.8:53');
1515

16-
$name = isset($argv[1]) ? $argv[1] : 'google.com';
16+
$name = $argv[1] ?? 'google.com';
1717

1818
$any = new Query($name, Message::TYPE_ANY, Message::CLASS_IN);
1919

src/Config/Config.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public static function loadResolvConfBlocking($path = null)
8282
throw new RuntimeException('Unable to load resolv.conf file "' . $path . '"');
8383
}
8484

85-
$matches = array();
85+
$matches = [];
8686
preg_match_all('/^nameserver\s+(\S+)\s*$/m', $contents, $matches);
8787

8888
$config = new self();
@@ -133,5 +133,5 @@ public static function loadWmicBlocking($command = null)
133133
return $config;
134134
}
135135

136-
public $nameservers = array();
136+
public $nameservers = [];
137137
}

src/Config/HostsFile.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public function getIpsForHost($name)
9898
{
9999
$name = strtolower($name);
100100

101-
$ips = array();
101+
$ips = [];
102102
foreach (preg_split('/\r?\n/', $this->contents) as $line) {
103103
$parts = preg_split('/\s+/', $line);
104104
$ip = array_shift($parts);
@@ -128,10 +128,10 @@ public function getHostsForIp($ip)
128128
// check binary representation of IP to avoid string case and short notation
129129
$ip = @inet_pton($ip);
130130
if ($ip === false) {
131-
return array();
131+
return [];
132132
}
133133

134-
$names = array();
134+
$names = [];
135135
foreach (preg_split('/\r?\n/', $this->contents) as $line) {
136136
$parts = preg_split('/\s+/', $line, -1, PREG_SPLIT_NO_EMPTY);
137137
$addr = (string) array_shift($parts);

0 commit comments

Comments
 (0)