Skip to content

Commit 4a2f711

Browse files
committed
Consistency updates for zendframework#30
- Ensures coding style within file is internally consistent.
1 parent ea72d78 commit 4a2f711

File tree

1 file changed

+27
-25
lines changed

1 file changed

+27
-25
lines changed

bin/update_hostname_validator.php

+27-25
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,24 @@
2626
exit(1);
2727
}
2828

29-
$newFileContent = []; // new file content
30-
$insertDone = false; // becomes 'true' when we find start of $validTlds declaration
31-
$insertFinish = false; // becomes 'true' when we find end of $validTlds declaration
32-
$checkOnly = isset($argv[1]) ? $argv[1] === '--check-only' : false;
33-
34-
$response = getOfficialTLDs();
35-
36-
$ianaVersion = getVersionFromString('Version', strtok($response->getBody(), "\n"));
29+
$newFileContent = []; // new file content
30+
$insertDone = false; // becomes 'true' when we find start of $validTlds declaration
31+
$insertFinish = false; // becomes 'true' when we find end of $validTlds declaration
32+
$checkOnly = isset($argv[1]) ? $argv[1] === '--check-only' : false;
33+
$response = getOfficialTLDs();
34+
$ianaVersion = getVersionFromString('Version', strtok($response->getBody(), "\n"));
3735
$validatorVersion = getVersionFromString('IanaVersion', file_get_contents(ZF2_HOSTNAME_VALIDATOR_FILE));
3836

39-
if ($ianaVersion > $validatorVersion && $checkOnly) {
40-
printf('TLDs must be updated, please run `php bin/update_hostname_validator.php` and push your changes%s', PHP_EOL);
37+
if ($checkOnly && $ianaVersion > $validatorVersion) {
38+
printf(
39+
'TLDs must be updated, please run `php bin/update_hostname_validator.php` and push your changes%s',
40+
PHP_EOL
41+
);
4142
exit(1);
4243
}
4344

4445
if ($checkOnly) {
45-
printf('TLDs are up to date%s', PHP_EOL);
46+
printf('TLDs are up-to-date%s', PHP_EOL);
4647
exit(0);
4748
}
4849

@@ -55,7 +56,7 @@
5556

5657
if ($insertDone === $insertFinish) {
5758
// Outside of $validTlds definition; keep line as-is
58-
$newFileContent []= $line;
59+
$newFileContent[] = $line;
5960
}
6061

6162
if ($insertFinish) {
@@ -65,8 +66,8 @@
6566
if ($insertDone) {
6667
// Detect where the $validTlds declaration ends
6768
if (preg_match('/^\s+\];\s*$/', $line)) {
68-
$newFileContent []= $line;
69-
$insertFinish = true;
69+
$newFileContent[] = $line;
70+
$insertFinish = true;
7071
}
7172

7273
continue;
@@ -75,22 +76,22 @@
7576
// Detect where the $validTlds declaration begins
7677
if (preg_match('/^\s+protected\s+\$validTlds\s+=\s+\[\s*$/', $line)) {
7778
$newFileContent = array_merge($newFileContent, getNewValidTlds($response->getBody()));
78-
$insertDone = true;
79+
$insertDone = true;
7980
}
8081
}
8182

8283
if (! $insertDone) {
83-
printf("Error: cannot find line with 'protected \$validTlds'%s", PHP_EOL);
84+
printf('Error: cannot find line with "protected $validTlds"%s', PHP_EOL);
8485
exit(1);
8586
}
8687

8788
if (!$insertFinish) {
88-
printf("Error: cannot find end of \$validTlds declaration%s", PHP_EOL);
89+
printf('Error: cannot find end of $validTlds declaration%s', PHP_EOL);
8990
exit(1);
9091
}
9192

9293
if (false === @file_put_contents(ZF2_HOSTNAME_VALIDATOR_FILE, $newFileContent)) {
93-
printf("Error: cannot write info file '%s'%s", ZF2_HOSTNAME_VALIDATOR_FILE, PHP_EOL);
94+
printf('Error: cannot write info file "%s"%s', ZF2_HOSTNAME_VALIDATOR_FILE, PHP_EOL);
9495
exit(1);
9596
}
9697

@@ -111,6 +112,7 @@ function getOfficialTLDs()
111112
]);
112113
$client->setUri(IANA_URL);
113114
$client->setMethod('GET');
115+
114116
$response = $client->send();
115117
if (! $response->isSuccess()) {
116118
throw new \Exception(sprintf("Error: cannot get '%s'%s", IANA_URL, PHP_EOL));
@@ -130,8 +132,8 @@ function getOfficialTLDs()
130132
function getVersionFromString($prefix, $string)
131133
{
132134
$matches = [];
133-
if (!preg_match(sprintf('/%s\s+((\d+)?)/', $prefix), $string, $matches)) {
134-
throw new \Exception('Error: cannot get last update date');
135+
if (! preg_match(sprintf('/%s\s+((\d+)?)/', $prefix), $string, $matches)) {
136+
throw new Exception('Error: cannot get last update date');
135137
}
136138

137139
return $matches[1];
@@ -179,13 +181,13 @@ function getPunycodeDecoder()
179181
}
180182

181183
$hostnameValidator = new Hostname();
182-
$reflection = new ReflectionClass(get_class($hostnameValidator));
183-
$method = $reflection->getMethod('decodePunycode');
184-
$method->setAccessible(true);
184+
$reflection = new ReflectionClass(get_class($hostnameValidator));
185+
$decodePunyCode = $reflection->getMethod('decodePunycode');
186+
$decodePunyCode->setAccessible(true);
185187

186-
return function ($encode) use ($hostnameValidator, $method) {
188+
return function ($encode) use ($hostnameValidator, $decodePunyCode) {
187189
if (strpos($encode, 'xn--') === 0) {
188-
return $method->invokeArgs($hostnameValidator, [substr($encode, 4)]);
190+
return $decodePunyCode->invokeArgs($hostnameValidator, [substr($encode, 4)]);
189191
}
190192
return $encode;
191193
};

0 commit comments

Comments
 (0)