Skip to content

Commit 18c8201

Browse files
committed
Improve code readability
1 parent fe91a0e commit 18c8201

File tree

5 files changed

+14
-19
lines changed

5 files changed

+14
-19
lines changed

data/pdp-PSL_FULL_5a3cc7f81795bb2e48e848af42d287b4.cache

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

data/pdp-RZD_FULL_f18a70477d29d525b9220612e2115345.cache

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

src/Converter.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,7 @@ private function addRule(array $list, array $rule_parts): array
116116
// "The domain and all rules must be canonicalized in the normal way
117117
// for hostnames - lower-case, Punycode (RFC 3492)."
118118
try {
119-
$tld = array_pop($rule_parts);
120-
$rule = $this->idnToAscii($tld);
119+
$rule = $this->idnToAscii(array_pop($rule_parts));
121120
} catch (Exception $e) {
122121
throw new CouldNotLoadRules($e->getMessage(), $e->getCode(), $e);
123122
}

src/Manager.php

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function getRules(string $url = self::PSL_URL, $ttl = null): Rules
9090
return new Rules($data);
9191
}
9292

93-
throw new CouldNotLoadRules('The public suffix list cache is corrupted: '.json_last_error_msg(), json_last_error());
93+
throw new CouldNotLoadRules(sprintf('The public suffix list cache is corrupted: %s', json_last_error_msg()), json_last_error());
9494
}
9595

9696
/**
@@ -110,12 +110,9 @@ public function refreshRules(string $url = self::PSL_URL, $ttl = null): bool
110110
static $converter;
111111

112112
$converter = $converter ?? new Converter();
113+
$data = json_encode($converter->convert($this->http->getContent($url)));
113114

114-
return $this->cache->set(
115-
$this->getCacheKey('PSL', $url),
116-
json_encode($converter->convert($this->http->getContent($url))),
117-
$this->filterTtl($ttl) ?? $this->ttl
118-
);
115+
return $this->cache->set($this->getCacheKey('PSL', $url), $data, $this->filterTtl($ttl) ?? $this->ttl);
119116
}
120117

121118
/**
@@ -139,11 +136,11 @@ public function getTLDs(string $url = self::RZD_URL, $ttl = null): TopLevelDomai
139136

140137
$data = json_decode($data ?? $this->cache->get($key), true);
141138
if (JSON_ERROR_NONE !== json_last_error()) {
142-
throw new CouldNotLoadTLDs('The root zone database cache is corrupted: '.json_last_error_msg(), json_last_error());
139+
throw new CouldNotLoadTLDs(sprintf('The root zone database cache is corrupted: %s', json_last_error_msg()), json_last_error());
143140
}
144141

145142
if (!isset($data['records'], $data['version'], $data['modifiedDate'])) {
146-
throw new CouldNotLoadTLDs(sprintf('The root zone database cache content is corrupted'));
143+
throw new CouldNotLoadTLDs('The root zone database cache content is corrupted');
147144
}
148145

149146
return new TopLevelDomains(
@@ -170,12 +167,9 @@ public function refreshTLDs(string $url = self::RZD_URL, $ttl = null): bool
170167
static $converter;
171168

172169
$converter = $converter ?? new TLDConverter();
170+
$data = json_encode($converter->convert($this->http->getContent($url)));
173171

174-
return $this->cache->set(
175-
$this->getCacheKey('RZD', $url),
176-
json_encode($converter->convert($this->http->getContent($url))),
177-
$this->filterTtl($ttl) ?? $this->ttl
178-
);
172+
return $this->cache->set($this->getCacheKey('RZD', $url), $data, $this->filterTtl($ttl) ?? $this->ttl);
179173
}
180174

181175
/**

src/TopLevelDomains.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,13 +225,15 @@ public function resolve($domain): Domain
225225
return $domain;
226226
}
227227

228+
$publicSuffix = null;
228229
$label = $domain->toAscii()->getLabel(0);
229230
foreach ($this as $tld) {
230231
if ($tld->getContent() === $label) {
231-
return $domain->resolve($tld);
232+
$publicSuffix = $tld;
233+
break;
232234
}
233235
}
234236

235-
return $domain->resolve(null);
237+
return $domain->resolve($publicSuffix);
236238
}
237239
}

0 commit comments

Comments
 (0)