Skip to content

Commit

Permalink
Apply fixes from StyleCI (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nyholm committed Apr 11, 2017
1 parent 98d38e3 commit 1380915
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 118 deletions.
6 changes: 4 additions & 2 deletions src/Factory/ServerRequestFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Psr\Http\Message\UploadedFileInterface;
use Interop\Http\Factory\ServerRequestFactoryInterface;
use Nyholm\Psr7\ServerRequest;
use Nyholm\Psr7\Factory\UriFactory;
use Nyholm\Psr7\UploadedFile;

/**
Expand Down Expand Up @@ -83,6 +82,7 @@ public function createServerRequestFromGlobals(): ServerRequestInterface
$server['REQUEST_METHOD'] = 'GET';
}
$headers = function_exists('getallheaders') ? getallheaders() : [];

return $this->createServerRequestFromArrays($_SERVER, $headers, $_COOKIE, $_GET, $_POST, $_FILES);
}

Expand All @@ -91,6 +91,7 @@ private function getMethodFromEnvironment(array $environment): string
if (false === isset($environment['REQUEST_METHOD'])) {
throw new InvalidArgumentException('Cannot determine HTTP method');
}

return $environment['REQUEST_METHOD'];
}

Expand All @@ -100,9 +101,10 @@ private function getUriFromEnvironmentWithHTTP(array $environment): \Psr\Http\Me
if ($uri->getScheme() === '') {
$uri = $uri->withScheme('http');
}

return $uri;
}

/**
* Return an UploadedFile instance array.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public function read($length): string
return fread($this->stream, $length);
}

public function getContents():string
public function getContents(): string
{
if (!isset($this->stream)) {
throw new \RuntimeException('Unable to read stream contents');
Expand Down
2 changes: 1 addition & 1 deletion tests/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public function testHostIsAddedFirst()
$r = new Request('GET', 'http://foo.com/baz?bar=bam', ['Foo' => 'Bar']);
$this->assertEquals([
'Host' => ['foo.com'],
'Foo' => ['Bar'],
'Foo' => ['Bar'],
], $r->getHeaders());
}

Expand Down
158 changes: 79 additions & 79 deletions tests/ServerRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ public function dataNormalizeFiles()
'Single file' => [
[
'file' => [
'name' => 'MyFile.txt',
'type' => 'text/plain',
'name' => 'MyFile.txt',
'type' => 'text/plain',
'tmp_name' => '/tmp/php/php1h4j1o',
'error' => '0',
'size' => '123',
'error' => '0',
'size' => '123',
],
],
[
Expand All @@ -39,11 +39,11 @@ public function dataNormalizeFiles()
'Empty file' => [
[
'image_file' => [
'name' => '',
'type' => '',
'name' => '',
'type' => '',
'tmp_name' => '',
'error' => '4',
'size' => '0',
'error' => '4',
'size' => '0',
],
],
[
Expand Down Expand Up @@ -117,18 +117,18 @@ public function dataNormalizeFiles()
'Multiple files' => [
[
'text_file' => [
'name' => 'MyFile.txt',
'type' => 'text/plain',
'name' => 'MyFile.txt',
'type' => 'text/plain',
'tmp_name' => '/tmp/php/php1h4j1o',
'error' => '0',
'size' => '123',
'error' => '0',
'size' => '123',
],
'image_file' => [
'name' => '',
'type' => '',
'name' => '',
'type' => '',
'tmp_name' => '',
'error' => '4',
'size' => '0',
'error' => '4',
'size' => '0',
],
],
[
Expand Down Expand Up @@ -175,35 +175,35 @@ public function dataNormalizeFiles()
'nested' => [
'name' => [
'other' => 'Flag.txt',
'test' => [
'test' => [
0 => 'Stuff.txt',
1 => '',
],
],
'type' => [
'other' => 'text/plain',
'test' => [
'test' => [
0 => 'text/plain',
1 => '',
],
],
'tmp_name' => [
'other' => '/tmp/php/hp9hskjhf',
'test' => [
'test' => [
0 => '/tmp/php/asifu2gp3',
1 => '',
],
],
'error' => [
'other' => '0',
'test' => [
'test' => [
0 => '0',
1 => '4',
],
],
'size' => [
'other' => '421',
'test' => [
'test' => [
0 => '32',
1 => '0',
],
Expand Down Expand Up @@ -279,34 +279,34 @@ public function testNormalizeFilesRaisesException()
public function dataGetUriFromGlobals()
{
$server = [
'PHP_SELF' => '/blog/article.php',
'GATEWAY_INTERFACE' => 'CGI/1.1',
'SERVER_ADDR' => 'Server IP: 217.112.82.20',
'SERVER_NAME' => 'www.blakesimpson.co.uk',
'SERVER_SOFTWARE' => 'Apache/2.2.15 (Win32) JRun/4.0 PHP/5.2.13',
'SERVER_PROTOCOL' => 'HTTP/1.0',
'REQUEST_METHOD' => 'POST',
'REQUEST_TIME' => 'Request start time: 1280149029',
'QUERY_STRING' => 'id=10&user=foo',
'DOCUMENT_ROOT' => '/path/to/your/server/root/',
'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'HTTP_ACCEPT_CHARSET' => 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
'PHP_SELF' => '/blog/article.php',
'GATEWAY_INTERFACE' => 'CGI/1.1',
'SERVER_ADDR' => 'Server IP: 217.112.82.20',
'SERVER_NAME' => 'www.blakesimpson.co.uk',
'SERVER_SOFTWARE' => 'Apache/2.2.15 (Win32) JRun/4.0 PHP/5.2.13',
'SERVER_PROTOCOL' => 'HTTP/1.0',
'REQUEST_METHOD' => 'POST',
'REQUEST_TIME' => 'Request start time: 1280149029',
'QUERY_STRING' => 'id=10&user=foo',
'DOCUMENT_ROOT' => '/path/to/your/server/root/',
'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'HTTP_ACCEPT_CHARSET' => 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
'HTTP_ACCEPT_ENCODING' => 'gzip,deflate',
'HTTP_ACCEPT_LANGUAGE' => 'en-gb,en;q=0.5',
'HTTP_CONNECTION' => 'keep-alive',
'HTTP_HOST' => 'www.blakesimpson.co.uk',
'HTTP_REFERER' => 'http://previous.url.com',
'HTTP_USER_AGENT' => 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-GB; rv:1.9.2.6) Gecko/20100625 Firefox/3.6.6 ( .NET CLR 3.5.30729)',
'HTTPS' => '1',
'REMOTE_ADDR' => '193.60.168.69',
'REMOTE_HOST' => 'Client server\'s host name',
'REMOTE_PORT' => '5390',
'SCRIPT_FILENAME' => '/path/to/this/script.php',
'SERVER_ADMIN' => 'webmaster@blakesimpson.co.uk',
'SERVER_PORT' => '80',
'SERVER_SIGNATURE' => 'Version signature: 5.123',
'SCRIPT_NAME' => '/blog/article.php',
'REQUEST_URI' => '/blog/article.php?id=10&user=foo',
'HTTP_CONNECTION' => 'keep-alive',
'HTTP_HOST' => 'www.blakesimpson.co.uk',
'HTTP_REFERER' => 'http://previous.url.com',
'HTTP_USER_AGENT' => 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-GB; rv:1.9.2.6) Gecko/20100625 Firefox/3.6.6 ( .NET CLR 3.5.30729)',
'HTTPS' => '1',
'REMOTE_ADDR' => '193.60.168.69',
'REMOTE_HOST' => 'Client server\'s host name',
'REMOTE_PORT' => '5390',
'SCRIPT_FILENAME' => '/path/to/this/script.php',
'SERVER_ADMIN' => 'webmaster@blakesimpson.co.uk',
'SERVER_PORT' => '80',
'SERVER_SIGNATURE' => 'Version signature: 5.123',
'SCRIPT_NAME' => '/blog/article.php',
'REQUEST_URI' => '/blog/article.php?id=10&user=foo',
];

return [
Expand Down Expand Up @@ -348,57 +348,57 @@ public function testGetUriFromGlobals($expected, $serverParams)
public function testFromGlobals()
{
$server = [
'PHP_SELF' => '/blog/article.php',
'GATEWAY_INTERFACE' => 'CGI/1.1',
'SERVER_ADDR' => 'Server IP: 217.112.82.20',
'SERVER_NAME' => 'www.blakesimpson.co.uk',
'SERVER_SOFTWARE' => 'Apache/2.2.15 (Win32) JRun/4.0 PHP/5.2.13',
'SERVER_PROTOCOL' => 'HTTP/1.0',
'REQUEST_METHOD' => 'POST',
'REQUEST_TIME' => 'Request start time: 1280149029',
'QUERY_STRING' => 'id=10&user=foo',
'DOCUMENT_ROOT' => '/path/to/your/server/root/',
'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'HTTP_ACCEPT_CHARSET' => 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
'PHP_SELF' => '/blog/article.php',
'GATEWAY_INTERFACE' => 'CGI/1.1',
'SERVER_ADDR' => 'Server IP: 217.112.82.20',
'SERVER_NAME' => 'www.blakesimpson.co.uk',
'SERVER_SOFTWARE' => 'Apache/2.2.15 (Win32) JRun/4.0 PHP/5.2.13',
'SERVER_PROTOCOL' => 'HTTP/1.0',
'REQUEST_METHOD' => 'POST',
'REQUEST_TIME' => 'Request start time: 1280149029',
'QUERY_STRING' => 'id=10&user=foo',
'DOCUMENT_ROOT' => '/path/to/your/server/root/',
'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'HTTP_ACCEPT_CHARSET' => 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
'HTTP_ACCEPT_ENCODING' => 'gzip,deflate',
'HTTP_ACCEPT_LANGUAGE' => 'en-gb,en;q=0.5',
'HTTP_CONNECTION' => 'keep-alive',
'HTTP_HOST' => 'www.blakesimpson.co.uk',
'HTTP_REFERER' => 'http://previous.url.com',
'HTTP_USER_AGENT' => 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-GB; rv:1.9.2.6) Gecko/20100625 Firefox/3.6.6 ( .NET CLR 3.5.30729)',
'HTTPS' => '1',
'REMOTE_ADDR' => '193.60.168.69',
'REMOTE_HOST' => 'Client server\'s host name',
'REMOTE_PORT' => '5390',
'SCRIPT_FILENAME' => '/path/to/this/script.php',
'SERVER_ADMIN' => 'webmaster@blakesimpson.co.uk',
'SERVER_PORT' => '80',
'SERVER_SIGNATURE' => 'Version signature: 5.123',
'SCRIPT_NAME' => '/blog/article.php',
'REQUEST_URI' => '/blog/article.php?id=10&user=foo',
'HTTP_CONNECTION' => 'keep-alive',
'HTTP_HOST' => 'www.blakesimpson.co.uk',
'HTTP_REFERER' => 'http://previous.url.com',
'HTTP_USER_AGENT' => 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-GB; rv:1.9.2.6) Gecko/20100625 Firefox/3.6.6 ( .NET CLR 3.5.30729)',
'HTTPS' => '1',
'REMOTE_ADDR' => '193.60.168.69',
'REMOTE_HOST' => 'Client server\'s host name',
'REMOTE_PORT' => '5390',
'SCRIPT_FILENAME' => '/path/to/this/script.php',
'SERVER_ADMIN' => 'webmaster@blakesimpson.co.uk',
'SERVER_PORT' => '80',
'SERVER_SIGNATURE' => 'Version signature: 5.123',
'SCRIPT_NAME' => '/blog/article.php',
'REQUEST_URI' => '/blog/article.php?id=10&user=foo',
];

$cookie = [
'logged-in' => 'yes!',
];

$post = [
'name' => 'Pesho',
'name' => 'Pesho',
'email' => 'pesho@example.com',
];

$get = [
'id' => 10,
'id' => 10,
'user' => 'foo',
];

$files = [
'file' => [
'name' => 'MyFile.txt',
'type' => 'text/plain',
'name' => 'MyFile.txt',
'type' => 'text/plain',
'tmp_name' => '/tmp/php/php1h4j1o',
'error' => UPLOAD_ERR_OK,
'size' => 123,
'error' => UPLOAD_ERR_OK,
'size' => 123,
],
];

Expand Down

0 comments on commit 1380915

Please sign in to comment.