Skip to content

Commit 4576ab9

Browse files
refactor(Bounce): Code smell complexity refactorisation
1 parent 7d7c626 commit 4576ab9

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

src/AbstractBounce.php

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -123,39 +123,31 @@ protected function initLoggerHelper(string $logDirectoryPath, string $loggerName
123123
*/
124124
protected function handleForwardedFor(string $ip, array $configs): string
125125
{
126+
$forwardedIp = null;
126127
if (empty($configs['forced_test_forwarded_ip'])) {
127128
$XForwardedForHeader = $this->getHttpRequestHeader('X-Forwarded-For');
128129
if (null !== $XForwardedForHeader) {
129130
$ipList = array_map('trim', array_values(array_filter(explode(',', $XForwardedForHeader))));
130131
$forwardedIp = end($ipList);
131-
if (is_string($forwardedIp) && $this->shouldTrustXforwardedFor($ip)) {
132-
$ip = $forwardedIp;
133-
} else {
134-
$this->logger->warning('', [
135-
'type' => 'NON_AUTHORIZED_X_FORWARDED_FOR_USAGE',
136-
'original_ip' => $ip,
137-
'x_forwarded_for_ip' => is_string($forwardedIp) ? $forwardedIp : 'type not as expected',
138-
]);
139-
}
140132
}
141133
} else if ($configs['forced_test_forwarded_ip'] === Constants::X_FORWARDED_DISABLED) {
142134
$this->logger->debug('', [
143135
'type' => 'DISABLED_X_FORWARDED_FOR_USAGE',
144136
'original_ip' => $ip,
145137
]);
146138
} else {
147-
$forwardedIp = $configs['forced_test_forwarded_ip'];
148-
if ($this->shouldTrustXforwardedFor($ip)) {
149-
$ip = (string) $forwardedIp;
150-
} else {
151-
$this->logger->warning('', [
152-
'type' => 'NON_AUTHORIZED_TEST_X_FORWARDED_FOR_USAGE',
153-
'original_ip' => $ip,
154-
'x_forwarded_for_ip_for_test' => $forwardedIp,
155-
]);
156-
}
139+
$forwardedIp = (string) $configs['forced_test_forwarded_ip'];
157140
}
158141

142+
if (is_string($forwardedIp) && $this->shouldTrustXforwardedFor($ip)) {
143+
$ip = $forwardedIp;
144+
} else {
145+
$this->logger->warning('', [
146+
'type' => 'NON_AUTHORIZED_X_FORWARDED_FOR_USAGE',
147+
'original_ip' => $ip,
148+
'x_forwarded_for_ip' => is_string($forwardedIp) ? $forwardedIp : 'type not as expected',
149+
]);
150+
}
159151
return $ip;
160152
}
161153

0 commit comments

Comments
 (0)