Skip to content

Commit a8df31d

Browse files
committed
refactor: update match utilities
1 parent e76dcb3 commit a8df31d

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

composer.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Web/Analytics/ParseLogCommand.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public function __invoke(): void
9898
}
9999

100100
// Resolve and check date
101-
$date = $line->match("/\[([\w\d\/\:]+)/")[1] ?? null;
101+
$date = $line->match("/\[([\w\d\/\:]+)/");
102102

103103
if (! $date) {
104104
continue;
@@ -111,9 +111,7 @@ public function __invoke(): void
111111
}
112112

113113
// Resolve and check URL
114-
$url = $line->match("/(GET|POST)\s([\w\/\.\-]+)/");
115-
116-
$url = str($url[2] ?? null)->trim();
114+
$url = str($line->match("/(GET|POST)\s([\w\/\.\-]+)/", match: 2));
117115

118116
// Empty URL
119117
if ($url->equals('')) {
@@ -126,14 +124,14 @@ public function __invoke(): void
126124
}
127125

128126
// Resolve and check IP
129-
$ip = $line->match("/^([\d\.\w\:]+)/")[1] ?? null;
127+
$ip = $line->match("/^([\d\.\w\:]+)/");
130128

131129
if (in_array($ip, self::IP_BLACKLIST, strict: true)) {
132130
continue;
133131
}
134132

135133
// Resolve and check UserAgent
136-
$userAgent = str($line->match('/"([\,\-\w\d\.\/\s\(\)\:\;\+\=\&\~\\\\\@\{\}\%\'\!\?\[\]\<\>\|]+)"$/')[1] ?? null)->lower();
134+
$userAgent = str($line->match('/"([\,\-\w\d\.\/\s\(\)\:\;\+\=\&\~\\\\\@\{\}\%\'\!\?\[\]\<\>\|]+)"$/'))->lower();
137135

138136
foreach (self::USER_AGENT_BLACKLIST as $blockedUserAgent) {
139137
if ($userAgent->contains($blockedUserAgent)) {

0 commit comments

Comments
 (0)