Skip to content

add missing type declarations #145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
"sebastian/comparator": ">=2"
},
"suggest": {
"ext-json": "To detect JSON responses with the ContentTypePlugin",
"ext-libxml": "To detect XML responses with the ContentTypePlugin",
"php-http/logger-plugin": "PSR-3 Logger plugin",
"php-http/cache-plugin": "PSR-6 Cache plugin",
"php-http/stopwatch-plugin": "Symfony Stopwatch plugin"
Expand Down
17 changes: 9 additions & 8 deletions src/Plugin/ContentTypePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ public function handleRequest(RequestInterface $request, callable $next, callabl
return $next($request);
}

/**
* @param $stream StreamInterface
*/
private function isJson($stream): bool
private function isJson(StreamInterface $stream): bool
{
if (!function_exists('json_decode')) {
return false;
}
$stream->rewind();

json_decode($stream->getContents());
Expand All @@ -108,17 +108,18 @@ private function isJson($stream): bool

/**
* @param $stream StreamInterface
*
* @return \SimpleXMLElement|false
*/
private function isXml($stream)
private function isXml(StreamInterface $stream): bool
{
if (!function_exists('simplexml_load_string')) {
return false;
}
$stream->rewind();

$previousValue = libxml_use_internal_errors(true);
$isXml = simplexml_load_string($stream->getContents());
libxml_use_internal_errors($previousValue);

return $isXml;
return false !== $isXml;
}
}
12 changes: 4 additions & 8 deletions src/Plugin/CookiePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,13 @@ public function handleRequest(RequestInterface $request, callable $next, callabl
/**
* Creates a cookie from a string.
*
* @param $setCookie
*
* @return Cookie|null
*
* @throws TransferException
*/
private function createCookie(RequestInterface $request, $setCookie)
private function createCookie(RequestInterface $request, string $setCookieHeader)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

: ?Cookie?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we'd need PHP 7.1 for that. Is there any reason why 2.x is php 7.0+ and not 7.1+. 7.0 is EOL already.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thats why i did not do it. but i wondered the same. happy to move to 7.1+. wdyt @Nyholm ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. Lets do PHP7.1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool! however, i'd prefer to do that in a separate pull request, as it will entail quite a lot of changes.

{
$parts = array_map('trim', explode(';', $setCookie));
$parts = array_map('trim', explode(';', $setCookieHeader));

if (empty($parts) || !strpos($parts[0], '=')) {
return null;
Expand Down Expand Up @@ -169,11 +167,9 @@ private function createCookie(RequestInterface $request, $setCookie)
/**
* Separates key/value pair from cookie.
*
* @param $part
*
* @return array
* @param string $part A single cookie value in format key=value
*/
private function createValueKey($part)
private function createValueKey(string $part): array
{
$parts = explode('=', $part, 2);
$key = trim($parts[0]);
Expand Down
17 changes: 3 additions & 14 deletions src/Plugin/DecoderPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,8 @@ public function handleRequest(RequestInterface $request, callable $next, callabl

/**
* Decode a response body given its Transfer-Encoding or Content-Encoding value.
*
* @param ResponseInterface $response Response to decode
*
* @return ResponseInterface New response decoded
*/
private function decodeResponse(ResponseInterface $response)
private function decodeResponse(ResponseInterface $response): ResponseInterface
{
$response = $this->decodeOnEncodingHeader('Transfer-Encoding', $response);

Expand All @@ -86,13 +82,8 @@ private function decodeResponse(ResponseInterface $response)

/**
* Decode a response on a specific header (content encoding or transfer encoding mainly).
*
* @param string $headerName Name of the header
* @param ResponseInterface $response Response
*
* @return ResponseInterface A new instance of the response decoded
*/
private function decodeOnEncodingHeader($headerName, ResponseInterface $response)
private function decodeOnEncodingHeader(string $headerName, ResponseInterface $response): ResponseInterface
{
if ($response->hasHeader($headerName)) {
$encodings = $response->getHeader($headerName);
Expand Down Expand Up @@ -123,11 +114,9 @@ private function decodeOnEncodingHeader($headerName, ResponseInterface $response
/**
* Decorate a stream given an encoding.
*
* @param string $encoding
*
* @return StreamInterface|false A new stream interface or false if encoding is not supported
*/
private function decorateStream($encoding, StreamInterface $stream)
private function decorateStream(string $encoding, StreamInterface $stream)
{
if ('chunked' === strtolower($encoding)) {
return new Encoding\DechunkStream($stream);
Expand Down