-
Notifications
You must be signed in to change notification settings - Fork 152
Small simplification #157
Small simplification #157
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -198,21 +198,18 @@ public static function marshalHeaders(array $server) | |
{ | ||
$headers = []; | ||
foreach ($server as $key => $value) { | ||
if ($value && strpos($key, 'HTTP_') === 0) { | ||
$name = strtr(substr($key, 5), '_', ' '); | ||
$name = strtr(ucwords(strtolower($name)), ' ', '-'); | ||
if ($value) { | ||
if (strpos($key, 'HTTP_') === 0) { | ||
$name = substr($key, 5); | ||
} elseif (strpos($key, 'CONTENT_') === 0) { | ||
$name = $key; | ||
} else { | ||
continue; | ||
} | ||
|
||
$name = strtr($name, '_', '-'); | ||
$name = strtolower($name); | ||
|
||
$headers[$name] = $value; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was this just dropped? Was there no coverage for it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you analyze it correctly - it basically does nothing.
As far as I saw there are test cases for all situations touched by these changes. |
||
continue; | ||
} | ||
|
||
if ($value && strpos($key, 'CONTENT_') === 0) { | ||
$name = substr($key, 8); // Content- | ||
$name = 'Content-' . (($name == 'MD5') ? $name : ucfirst(strtolower($name))); | ||
$name = strtolower($name); | ||
$headers[$name] = $value; | ||
continue; | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code has a much higher cyclomatic complexity, and is also harder to understand, IMO
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I read it in following way:
HTTP_
- drop prefixCONTENT_
- take it as is_
with-
in keyAdded cyclomatic complexity is only because we've decoupled common operations for
HTTP_*
andCONTENT_*
keys, otherwise it is the same. I thought there is no reason to duplicate 3 exactly the same lines in 2 neighbor blocks.