Skip to content

Commit 9b344cf

Browse files
committed
Improve Rules::getPublicSuffixLengthFromSection codebase with early return
1 parent 55246c1 commit 9b344cf

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ All Notable changes to `PHP Domain Parser` starting from the **5.x** series will
88

99
- `DomainName::withRootLabel`, `DomainName::withoutRootLabel`, `DomainName::isAbsolute` methods to handle absolute domain names.
1010
- `DomainName::when` to allow conditionable when building the domain.
11+
- `Rules` can now be serialize and unserialize.
12+
- `TopLevelDomains` can now be serialize and unserialize.
1113

1214
### Fixed
1315

src/Rules.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,19 +258,20 @@ private function getPublicSuffixLengthFromSection(DomainName $domain, string $se
258258
foreach ($domain->toAscii() as $label) {
259259
//match exception rule
260260
if (isset($rules[$label]['!'])) {
261-
break;
261+
return $labelCount;
262262
}
263263

264264
//match wildcard rule
265265
if (array_key_exists('*', $rules)) {
266266
++$labelCount;
267-
break;
267+
268+
return $labelCount;
268269
}
269270

270271
//no match found
271272
if (!array_key_exists($label, $rules)) {
272273
if (self::PRIVATE_DOMAINS !== $section) {
273-
break;
274+
return $labelCount;
274275
}
275276

276277
// Suffix MATCHES default domain
@@ -283,7 +284,7 @@ private function getPublicSuffixLengthFromSection(DomainName $domain, string $se
283284
return 0;
284285
}
285286

286-
break;
287+
return $labelCount;
287288
}
288289

289290
++$labelCount;

0 commit comments

Comments
 (0)