Skip to content

Commit

Permalink
improved coding style
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Jun 19, 2015
1 parent d3e44f5 commit 78a872a
Show file tree
Hide file tree
Showing 45 changed files with 380 additions and 379 deletions.
2 changes: 1 addition & 1 deletion src/Bridges/HttpDI/SessionExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function loadConfiguration()

if ($this->debugMode && $config['debugger']) {
$session->addSetup('@Tracy\Bar::addPanel', [
new Nette\DI\Statement('Nette\Bridges\HttpTracy\SessionPanel')
new Nette\DI\Statement('Nette\Bridges\HttpTracy\SessionPanel'),
]);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Http/IResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ interface IResponse
S303_POST_GET = 303,
S304_NOT_MODIFIED = 304,
S305_USE_PROXY = 305,
S307_TEMPORARY_REDIRECT= 307,
S307_TEMPORARY_REDIRECT = 307,
S400_BAD_REQUEST = 400,
S401_UNAUTHORIZED = 401,
S402_PAYMENT_REQUIRED = 402,
Expand Down
3 changes: 2 additions & 1 deletion src/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,8 @@ public function detectLanguage(array $langs)
foreach ($matches[1] as $key => $value) {
$q = $matches[2][$key] === '' ? 1.0 : (float) $matches[2][$key];
if ($q > $max) {
$max = $q; $lang = $value;
$max = $q;
$lang = $value;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Http/RequestFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public function createHttpRequest()
}

// raw body
$rawBodyCallback = function() {
$rawBodyCallback = function () {
static $rawBody;

if (PHP_VERSION_ID >= 50600) {
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ private function checkHeaders()
if (headers_sent($file, $line)) {
throw new Nette\InvalidStateException('Cannot send header after HTTP headers have been sent' . ($file ? " (output started at $file:$line)." : '.'));

} elseif ($this->warnOnBuffer && ob_get_length() && !array_filter(ob_get_status(TRUE), function($i) { return !$i['chunk_size']; })) {
} elseif ($this->warnOnBuffer && ob_get_length() && !array_filter(ob_get_status(TRUE), function ($i) { return !$i['chunk_size']; })) {
trigger_error('Possible problem: you are sending a HTTP header while already having some data in output buffer. Try Tracy\OutputDebugger or start session earlier.', E_USER_NOTICE);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/Http/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public function regenerateId()
{
if (self::$started && !$this->regenerated) {
if (headers_sent($file, $line)) {
throw new Nette\InvalidStateException("Cannot regenerate session ID after HTTP headers have been sent" . ($file ? " (output started at $file:$line)." : "."));
throw new Nette\InvalidStateException('Cannot regenerate session ID after HTTP headers have been sent' . ($file ? " (output started at $file:$line)." : '.'));
}
session_regenerate_id(TRUE);
session_write_close();
Expand Down Expand Up @@ -413,7 +413,7 @@ private function configure(array $config)

} else {
if (defined('SID')) {
throw new Nette\InvalidStateException("Unable to set 'session.$key' to value '$value' when session has been started" . ($this->started ? "." : " by session.auto_start or session_start()."));
throw new Nette\InvalidStateException("Unable to set 'session.$key' to value '$value' when session has been started" . ($this->started ? '.' : ' by session.auto_start or session_start().'));
}
if (isset($special[$key])) {
$key = "session_$key";
Expand Down Expand Up @@ -479,7 +479,7 @@ public function setCookieParameters($path, $domain = NULL, $secure = NULL)
return $this->setOptions([
'cookie_path' => $path,
'cookie_domain' => $domain,
'cookie_secure' => $secure
'cookie_secure' => $secure,
]);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Http/SessionSection.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class SessionSection extends Nette\Object implements \IteratorAggregate, \ArrayA
public function __construct(Session $session, $name)
{
if (!is_string($name)) {
throw new Nette\InvalidArgumentException("Session namespace must be a string, " . gettype($name) . " given.");
throw new Nette\InvalidArgumentException('Session namespace must be a string, ' . gettype($name) . ' given.');
}

$this->session = $session;
Expand Down
4 changes: 2 additions & 2 deletions src/Http/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ public function canonicalize()
{
$this->path = preg_replace_callback(
'#[^!$&\'()*+,/:;=@%]+#',
function($m) { return rawurlencode($m[0]); },
function ($m) { return rawurlencode($m[0]); },
self::unescape($this->path, '%/')
);
$this->host = strtolower($this->host);
Expand Down Expand Up @@ -474,7 +474,7 @@ public static function unescape($s, $reserved = '%;/?:@&=+$,')
if ($reserved !== '') {
$s = preg_replace_callback(
'#%(' . substr(chunk_split(bin2hex($reserved), 2, '|'), 0, -1) . ')#i',
function($m) { return '%25' . strtoupper($m[1]); },
function ($m) { return '%25' . strtoupper($m[1]); },
$s
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Http/UserStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class UserStorage extends Nette\Object implements Nette\Security\IUserStorage
private $sessionSection;


public function __construct(Session $sessionHandler)
public function __construct(Session $sessionHandler)
{
$this->sessionHandler = $sessionHandler;
}
Expand Down
6 changes: 3 additions & 3 deletions tests/Http.DI/HttpExtension.defaultHeaders.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ $container = new Container1;
$container->initialize();

$headers = headers_list();
Assert::contains( 'X-Frame-Options: SAMEORIGIN', $headers );
Assert::contains( 'Content-Type: text/html; charset=utf-8', $headers );
Assert::contains( 'X-Powered-By: Nette Framework', $headers );
Assert::contains('X-Frame-Options: SAMEORIGIN', $headers);
Assert::contains('Content-Type: text/html; charset=utf-8', $headers);
Assert::contains('X-Powered-By: Nette Framework', $headers);
14 changes: 7 additions & 7 deletions tests/Http.DI/HttpExtension.headers.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@ $container = new Container1;
$container->initialize();

$headers = headers_list();
Assert::contains( 'X-Frame-Options: SAMEORIGIN', $headers );
Assert::contains( 'Content-Type: text/html; charset=utf-8', $headers );
Assert::contains( 'X-Powered-By: Nette Framework', $headers );
Assert::contains( 'A: b', $headers );
Assert::notContains( 'C:', $headers );
Assert::contains('X-Frame-Options: SAMEORIGIN', $headers);
Assert::contains('Content-Type: text/html; charset=utf-8', $headers);
Assert::contains('X-Powered-By: Nette Framework', $headers);
Assert::contains('A: b', $headers);
Assert::notContains('C:', $headers);



echo ' '; @ob_flush(); flush();

Assert::true( headers_sent() );
Assert::true(headers_sent());

Assert::error(function() use ($container) {
Assert::error(function () use ($container) {
$container->initialize();
}, [
[E_WARNING, 'Cannot modify header information - headers already sent %a%'],
Expand Down
30 changes: 15 additions & 15 deletions tests/Http/FileUpload.basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use Nette\Http\FileUpload,
require __DIR__ . '/../bootstrap.php';


test(function() {
test(function () {
$upload = new FileUpload([
'name' => 'readme.txt',
'type' => 'text/plain',
Expand All @@ -20,19 +20,19 @@ test(function() {
'size' => 209,
]);

Assert::same( 'readme.txt', $upload->getName() );
Assert::same( 'readme.txt', $upload->getSanitizedName() );
Assert::same( 209, $upload->getSize() );
Assert::same( __DIR__ . '/files/file.txt', $upload->getTemporaryFile() );
Assert::same( __DIR__ . '/files/file.txt', (string) $upload );
Assert::same( 0, $upload->getError() );
Assert::true( $upload->isOk() );
Assert::false( $upload->isImage() );
Assert::same( file_get_contents(__DIR__ . '/files/file.txt'), $upload->getContents() );
Assert::same('readme.txt', $upload->getName());
Assert::same('readme.txt', $upload->getSanitizedName());
Assert::same(209, $upload->getSize());
Assert::same(__DIR__ . '/files/file.txt', $upload->getTemporaryFile());
Assert::same(__DIR__ . '/files/file.txt', (string) $upload);
Assert::same(0, $upload->getError());
Assert::true($upload->isOk());
Assert::false($upload->isImage());
Assert::same(file_get_contents(__DIR__ . '/files/file.txt'), $upload->getContents());
});


test(function() {
test(function () {
$upload = new FileUpload([
'name' => '../.image.png',
'type' => 'text/plain',
Expand All @@ -41,8 +41,8 @@ test(function() {
'size' => 209,
]);

Assert::same( '../.image.png', $upload->getName() );
Assert::same( 'image.png', $upload->getSanitizedName() );
Assert::same( 'image/png', $upload->getContentType() );
Assert::true( $upload->isImage() );
Assert::same('../.image.png', $upload->getName());
Assert::same('image.png', $upload->getSanitizedName());
Assert::same('image/png', $upload->getContentType());
Assert::true($upload->isImage());
});
50 changes: 25 additions & 25 deletions tests/Http/Helpers.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,37 @@ use Nette\Http\Helpers,
require __DIR__ . '/../bootstrap.php';


test(function() {
Assert::true( Helpers::ipMatch('192.168.68.233', '192.168.68.233') );
Assert::false( Helpers::ipMatch('192.168.68.234', '192.168.68.233') );
Assert::true( Helpers::ipMatch('192.168.64.0', '192.168.68.233/20') );
Assert::false( Helpers::ipMatch('192.168.63.255', '192.168.68.233/20') );
Assert::true( Helpers::ipMatch('192.168.79.254', '192.168.68.233/20') );
Assert::false( Helpers::ipMatch('192.168.80.0', '192.168.68.233/20') );
Assert::true( Helpers::ipMatch('127.0.0.1', '192.168.68.233/0') );
Assert::false( Helpers::ipMatch('127.0.0.1', '192.168.68.233/33') );

Assert::false( Helpers::ipMatch('127.0.0.1', '7F00:0001::') );
test(function () {
Assert::true(Helpers::ipMatch('192.168.68.233', '192.168.68.233'));
Assert::false(Helpers::ipMatch('192.168.68.234', '192.168.68.233'));
Assert::true(Helpers::ipMatch('192.168.64.0', '192.168.68.233/20'));
Assert::false(Helpers::ipMatch('192.168.63.255', '192.168.68.233/20'));
Assert::true(Helpers::ipMatch('192.168.79.254', '192.168.68.233/20'));
Assert::false(Helpers::ipMatch('192.168.80.0', '192.168.68.233/20'));
Assert::true(Helpers::ipMatch('127.0.0.1', '192.168.68.233/0'));
Assert::false(Helpers::ipMatch('127.0.0.1', '192.168.68.233/33'));

Assert::false(Helpers::ipMatch('127.0.0.1', '7F00:0001::'));
});



test(function() {
Assert::true( Helpers::ipMatch('2001:db8:0:0:0:0:0:0', '2001:db8::') );
Assert::false( Helpers::ipMatch('2001:db8:0:0:0:0:0:0', '2002:db8::') );
Assert::false( Helpers::ipMatch('2001:db8:0:0:0:0:0:1', '2001:db8::') );
Assert::true( Helpers::ipMatch('2001:db8:0:0:0:0:0:0', '2001:db8::/48') );
Assert::true( Helpers::ipMatch('2001:db8:0:ffff:ffff:ffff:ffff:ffff', '2001:db8::/48') );
Assert::false( Helpers::ipMatch('2001:db8:1::', '2001:db8::/48') );
Assert::false( Helpers::ipMatch('2001:db8:0:0:0:0:0:0', '2001:db8::/129') );
Assert::false( Helpers::ipMatch('2001:db8:0:0:0:0:0:0', '32.1.13.184/32') );
test(function () {
Assert::true(Helpers::ipMatch('2001:db8:0:0:0:0:0:0', '2001:db8::'));
Assert::false(Helpers::ipMatch('2001:db8:0:0:0:0:0:0', '2002:db8::'));
Assert::false(Helpers::ipMatch('2001:db8:0:0:0:0:0:1', '2001:db8::'));
Assert::true(Helpers::ipMatch('2001:db8:0:0:0:0:0:0', '2001:db8::/48'));
Assert::true(Helpers::ipMatch('2001:db8:0:ffff:ffff:ffff:ffff:ffff', '2001:db8::/48'));
Assert::false(Helpers::ipMatch('2001:db8:1::', '2001:db8::/48'));
Assert::false(Helpers::ipMatch('2001:db8:0:0:0:0:0:0', '2001:db8::/129'));
Assert::false(Helpers::ipMatch('2001:db8:0:0:0:0:0:0', '32.1.13.184/32'));
});



test(function() {
Assert::same( 'Tue, 15 Nov 1994 08:12:31 GMT', Helpers::formatDate('1994-11-15T08:12:31+0000') );
Assert::same( 'Tue, 15 Nov 1994 08:12:31 GMT', Helpers::formatDate('1994-11-15T10:12:31+0200') );
Assert::same( 'Tue, 15 Nov 1994 08:12:31 GMT', Helpers::formatDate(new DateTime('1994-11-15T06:12:31-0200')) );
Assert::same( 'Tue, 15 Nov 1994 08:12:31 GMT', Helpers::formatDate(784887151) );
test(function () {
Assert::same('Tue, 15 Nov 1994 08:12:31 GMT', Helpers::formatDate('1994-11-15T08:12:31+0000'));
Assert::same('Tue, 15 Nov 1994 08:12:31 GMT', Helpers::formatDate('1994-11-15T10:12:31+0200'));
Assert::same('Tue, 15 Nov 1994 08:12:31 GMT', Helpers::formatDate(new DateTime('1994-11-15T06:12:31-0200')));
Assert::same('Tue, 15 Nov 1994 08:12:31 GMT', Helpers::formatDate(784887151));
});
22 changes: 11 additions & 11 deletions tests/Http/Request.detectLanguage.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,36 @@ use Nette\Http,
require __DIR__ . '/../bootstrap.php';


test(function() {
test(function () {
$headers = ['Accept-Language' => 'en, cs'];
$request = new Http\Request(new Http\UrlScript, NULL, NULL, NULL, NULL, $headers);

Assert::same( 'en', $request->detectLanguage(['en', 'cs']) );
Assert::same( 'en', $request->detectLanguage(['cs', 'en']) );
Assert::null( $request->detectLanguage(['xx']) );
Assert::same('en', $request->detectLanguage(['en', 'cs']));
Assert::same('en', $request->detectLanguage(['cs', 'en']));
Assert::null($request->detectLanguage(['xx']));
});


test(function() {
test(function () {
$headers = ['Accept-Language' => 'da, en-gb;q=0.8, en;q=0.7'];
$request = new Http\Request(new Http\UrlScript, NULL, NULL, NULL, NULL, $headers);

Assert::same( 'en-gb', $request->detectLanguage(['en', 'en-gb']) );
Assert::same( 'en', $request->detectLanguage(['en']) );
Assert::same('en-gb', $request->detectLanguage(['en', 'en-gb']));
Assert::same('en', $request->detectLanguage(['en']));
});


test(function() {
test(function () {
$headers = [];
$request = new Http\Request(new Http\UrlScript, NULL, NULL, NULL, NULL, $headers);

Assert::null( $request->detectLanguage(['en']) );
Assert::null($request->detectLanguage(['en']));
});


test(function() {
test(function () {
$headers = ['Accept-Language' => 'garbage'];
$request = new Http\Request(new Http\UrlScript, NULL, NULL, NULL, NULL, $headers);

Assert::null( $request->detectLanguage(['en']) );
Assert::null($request->detectLanguage(['en']));
});
16 changes: 8 additions & 8 deletions tests/Http/Request.files.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@ $_FILES = [
$factory = new Http\RequestFactory;
$request = $factory->createHttpRequest();

Assert::type( 'Nette\Http\FileUpload', $request->files['file1'] );
Assert::type( 'Nette\Http\FileUpload', $request->files['file2'][2] );
Assert::type( 'Nette\Http\FileUpload', $request->files['file3']['y']['z'] );
Assert::type( 'Nette\Http\FileUpload', $request->files['file3'][1] );
Assert::type('Nette\Http\FileUpload', $request->files['file1']);
Assert::type('Nette\Http\FileUpload', $request->files['file2'][2]);
Assert::type('Nette\Http\FileUpload', $request->files['file3']['y']['z']);
Assert::type('Nette\Http\FileUpload', $request->files['file3'][1]);

Assert::false( isset($request->files['file0']) );
Assert::true( isset($request->files['file1']) );
Assert::false(isset($request->files['file0']));
Assert::true(isset($request->files['file1']));

Assert::null( $request->getFile('empty1') );
Assert::same( [NULL], $request->getFile('empty2') );
Assert::null($request->getFile('empty1'));
Assert::same([NULL], $request->getFile('empty2'));
10 changes: 5 additions & 5 deletions tests/Http/Request.getRawBody.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ use Nette\Http,
require __DIR__ . '/../bootstrap.php';


test(function() {
$request = new Http\Request(new Http\UrlScript, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, function() {
test(function () {
$request = new Http\Request(new Http\UrlScript, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, function () {
return 'raw body';
});

Assert::same( 'raw body', $request->getRawBody() );
Assert::same('raw body', $request->getRawBody());
});


test(function() {
test(function () {
$request = new Http\Request(new Http\UrlScript);

Assert::null( $request->getRawBody() );
Assert::null($request->getRawBody());
});
6 changes: 3 additions & 3 deletions tests/Http/Request.headers.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ use Nette\Http,
require __DIR__ . '/../bootstrap.php';


test(function() {
test(function () {
$request = new Http\Request(new Http\UrlScript);
Assert::same([], $request->getHeaders());
});

test(function() {
test(function () {
$request = new Http\Request(new Http\UrlScript, NULL, NULL, NULL, NULL, []);
Assert::same([], $request->getHeaders());
});

test(function() {
test(function () {
$request = new Http\Request(new Http\UrlScript, NULL, NULL, NULL, NULL, [
'one' => '1',
'TWO' => '2',
Expand Down
Loading

0 comments on commit 78a872a

Please sign in to comment.