Skip to content

Commit

Permalink
formatting and comment tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
sndsgd committed Jul 14, 2016
1 parent e0d7974 commit 29c88a1
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 21 deletions.
7 changes: 4 additions & 3 deletions src/http/HeaderCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class HeaderCollection
protected $keyMap = [];

/**
* Retrieve a key that can be used in a hashmap to prevent duplicate keys
*
* @param string $key
* @param bool $register Whether to register a new key
* @return string
Expand All @@ -26,8 +28,7 @@ protected function getKey(string $key, bool $register = false): string
$lowercaseKey = strtolower($key);
if (isset($this->keyMap[$lowercaseKey])) {
$key = $this->keyMap[$lowercaseKey];
}
elseif ($register) {
} elseif ($register) {
$this->keyMap[$lowercaseKey] = $key;
}
return $key;
Expand Down Expand Up @@ -99,7 +100,7 @@ public function get(string $key): string
/**
* Get multiple header values
*
* @param string $key
* @param string ...$keys
* @return array<string>
*/
public function getMultiple(string ...$keys): array
Expand Down
8 changes: 4 additions & 4 deletions src/http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Request implements RequestParameterDecoderInterface
/**
* Headers are parsed and cached here
*
* @var array<string>
* @var array<string,string>
*/
protected $headers;

Expand Down Expand Up @@ -135,11 +135,11 @@ public function getIp(): string
*/
public function getHeader(string $name, string $default = ""): string
{
if (!$this->headers) {
if ($this->headers === null) {
$this->headers = $this->readHeaders();
}
$name = strtolower($name);
return $this->headers[$name] ?? $default;
$lowercaseName = strtolower($name);
return $this->headers[$lowercaseName] ?? $default;
}

/**
Expand Down
5 changes: 5 additions & 0 deletions src/http/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ class Response
*/
protected $statusText = "OK";

/**
* @var \sndsgd\http\HeaderCollection
*/
protected $headers;

/**
* Once the body has been generated it is stored here
*
Expand Down
8 changes: 4 additions & 4 deletions src/http/data/decoder/MultipartDataDecoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ public function decode(): array
if ($this->fileCount < $this->maxFileCount) {
$value = $this->getFileFromField($name, $filename, $contentType);
$this->values->addValue($name, $value);
}
else {
} else {

}

Expand Down Expand Up @@ -224,7 +223,8 @@ protected function getFieldHeader()
);
}

list($match, $name, $filename) = array_pad($matches, 3, "");
# we have no need for the entire match, so we drop it here
list( , $name, $filename) = array_pad($matches, 3, "");

# if a filename was in the content disposition
# attempt to find its content type in the field header
Expand Down Expand Up @@ -264,7 +264,7 @@ private function getValueFromField()
/**
* Allow for stubbing the result of tempnam using reflection
*
* @return bool
* @return string
*/
protected function getTempFilePath()
{
Expand Down
16 changes: 8 additions & 8 deletions src/http/data/decoder/QueryStringDecoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,21 @@ public function __construct(
}

/**
* Decode a urlencoded parameter pair
* Decode a urlencoded parameter key value pair
*
* @param string $pair
* @param string $keyValuePair
* @return array<string> The decoded key and value
*/
public function decodePair(string $pair): array
public function decodePair(string $keyValuePair): array
{
# more than a handful of clients like to use '+' characters
# when encoding data that is (almost) compliant with rfc 3986
# this is a hack that allows for it
if (strpos($pair, "+") !== false) {
$pair = str_replace("+", " ", $pair);
if (strpos($keyValuePair, "+") !== false) {
$keyValuePair = str_replace("+", " ", $keyValuePair);
}

$parts = explode("=", $pair, 2);
$parts = explode("=", $keyValuePair, 2);
$key = rawurldecode($parts[0]);

# interpret a key with an empty value as `null`
Expand All @@ -76,8 +76,8 @@ public function decodePair(string $pair): array
*/
public function decode($query): array
{
foreach (explode("&", $query) as $pair) {
list($key, $value) = $this->decodePair($pair);
foreach (explode("&", $query) as $keyValuePair) {
list($key, $value) = $this->decodePair($keyValuePair);
$this->values->addValue($key, $value);
}
return $this->values->getValues();
Expand Down
3 changes: 1 addition & 2 deletions src/http/request/BodyDecoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@ protected function parsePost()
]);
\sndsgd\Arr::addValue($ret, $name, $file);
}
}
else {
} else {
$file = $this->createUploadedFile($info);
\sndsgd\Arr::addValue($ret, $name, $file);
}
Expand Down

0 comments on commit 29c88a1

Please sign in to comment.