Skip to content

Commit d45ab0f

Browse files
committed
coding style
1 parent e7347b1 commit d45ab0f

18 files changed

Lines changed: 66 additions & 70 deletions

src/Bridges/HttpDI/HttpExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ private function sendHeaders()
116116
$this->initialization->addBody('$cspNonce = base64_encode(random_bytes(16));');
117117
$value = Nette\DI\ContainerBuilder::literal(
118118
'str_replace(?, ? . $cspNonce, ?)',
119-
["'nonce", "'nonce-", $value]
119+
["'nonce", "'nonce-", $value],
120120
);
121121
}
122122
$headers['Content-Security-Policy' . ($key === 'csp' ? '' : '-Report-Only')] = $value;
@@ -135,7 +135,7 @@ private function sendHeaders()
135135

136136
$this->initialization->addBody(
137137
'Nette\Http\Helpers::initCookie($this->getService(?), $response);',
138-
[$this->prefix('request')]
138+
[$this->prefix('request')],
139139
);
140140
}
141141

src/Http/FileUpload.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public function move(string $dest)
181181
[$this->tmpName, $dest],
182182
function (string $message) use ($dest): void {
183183
throw new Nette\InvalidStateException("Unable to move uploaded file '$this->tmpName' to '$dest'. $message");
184-
}
184+
},
185185
);
186186
@chmod($dest, 0666); // @ - possible low permission to chmod
187187
$this->tmpName = $dest;

src/Http/Helpers.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public static function formatDate($time): string
4141
public static function ipMatch(string $ip, string $mask): bool
4242
{
4343
[$mask, $size] = explode('/', $mask . '/');
44-
$tmp = function (int $n): string { return sprintf('%032b', $n); };
44+
$tmp = fn(int $n): string => sprintf('%032b', $n);
4545
$ip = implode('', array_map($tmp, unpack('N*', inet_pton($ip))));
4646
$mask = implode('', array_map($tmp, unpack('N*', inet_pton($mask))));
4747
$max = strlen($ip);

src/Http/IResponse.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ function setCookie(
220220
string $path = null,
221221
string $domain = null,
222222
bool $secure = null,
223-
bool $httpOnly = null
223+
bool $httpOnly = null,
224224
);
225225

226226
/**

src/Http/Request.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function __construct(
7070
string $method = null,
7171
string $remoteAddress = null,
7272
string $remoteHost = null,
73-
callable $rawBodyCallback = null
73+
callable $rawBodyCallback = null,
7474
) {
7575
$this->url = $url;
7676
$this->post = (array) $post;

src/Http/RequestFactory.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,7 @@ public function fromGlobals(): Request
7676
$this->getMethod(),
7777
$remoteAddr,
7878
$remoteHost,
79-
function (): string {
80-
return file_get_contents('php://input');
81-
}
79+
fn(): string => file_get_contents('php://input'),
8280
);
8381
}
8482

@@ -271,9 +269,7 @@ private function getClient(Url $url): array
271269
: null;
272270

273271
// use real client address and host if trusted proxy is used
274-
$usingTrustedProxy = $remoteAddr && array_filter($this->proxies, function (string $proxy) use ($remoteAddr): bool {
275-
return Helpers::ipMatch($remoteAddr, $proxy);
276-
});
272+
$usingTrustedProxy = $remoteAddr && array_filter($this->proxies, fn(string $proxy): bool => Helpers::ipMatch($remoteAddr, $proxy));
277273
if ($usingTrustedProxy) {
278274
empty($_SERVER['HTTP_FORWARDED'])
279275
? $this->useNonstandardProxy($url, $remoteAddr, $remoteHost)
@@ -339,11 +335,13 @@ private function useNonstandardProxy(Url $url, &$remoteAddr, &$remoteHost): void
339335
}
340336

341337
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
342-
$xForwardedForWithoutProxies = array_filter(explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']), function (string $ip): bool {
343-
return !array_filter($this->proxies, function (string $proxy) use ($ip): bool {
344-
return filter_var(trim($ip), FILTER_VALIDATE_IP) !== false && Helpers::ipMatch(trim($ip), $proxy);
345-
});
346-
});
338+
$xForwardedForWithoutProxies = array_filter(
339+
explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']),
340+
fn(string $ip): bool => !array_filter(
341+
$this->proxies,
342+
fn(string $proxy): bool => filter_var(trim($ip), FILTER_VALIDATE_IP) !== false && Helpers::ipMatch(trim($ip), $proxy),
343+
),
344+
);
347345
if ($xForwardedForWithoutProxies) {
348346
$remoteAddr = trim(end($xForwardedForWithoutProxies));
349347
$xForwardedForRealIpKey = key($xForwardedForWithoutProxies);

src/Http/Response.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public function sendAsFile(string $fileName)
148148
$this->setHeader(
149149
'Content-Disposition',
150150
'attachment; filename="' . str_replace('"', '', $fileName) . '"; '
151-
. "filename*=utf-8''" . rawurlencode($fileName)
151+
. "filename*=utf-8''" . rawurlencode($fileName),
152152
);
153153
return $this;
154154
}
@@ -262,7 +262,7 @@ public function setCookie(
262262
string $domain = null,
263263
bool $secure = null,
264264
bool $httpOnly = null,
265-
string $sameSite = null
265+
string $sameSite = null,
266266
) {
267267
self::checkHeaders();
268268
$options = [
@@ -283,7 +283,7 @@ public function setCookie(
283283
$options['path'] . ($sameSite ? "; SameSite=$sameSite" : ''),
284284
$options['domain'],
285285
$options['secure'],
286-
$options['httponly']
286+
$options['httponly'],
287287
);
288288
}
289289
return $this;
@@ -309,7 +309,7 @@ private function checkHeaders(): void
309309
} elseif (
310310
$this->warnOnBuffer &&
311311
ob_get_length() &&
312-
!array_filter(ob_get_status(true), function (array $i): bool { return !$i['chunk_size']; })
312+
!array_filter(ob_get_status(true), fn(array $i): bool => !$i['chunk_size'])
313313
) {
314314
trigger_error('Possible problem: you are sending a HTTP header while already having some data in output buffer. Try Tracy\OutputDebugger or send cookies/start session earlier.');
315315
}

src/Http/Session.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ public function setOptions(array $options)
336336
if (!isset($allowed["session.$normKey"])) {
337337
$hint = substr((string) Nette\Utils\Helpers::getSuggestion(array_keys($allowed), "session.$normKey"), 8);
338338
if ($key !== $normKey) {
339-
$hint = preg_replace_callback('#_(.)#', function ($m) { return strtoupper($m[1]); }, $hint); // snake_case -> camelCase
339+
$hint = preg_replace_callback('#_(.)#', fn($m) => strtoupper($m[1]), $hint); // snake_case -> camelCase
340340
}
341341
throw new Nette\InvalidStateException("Invalid session configuration option '$key'" . ($hint ? ", did you mean '$hint'?" : '.'));
342342
}
@@ -411,7 +411,7 @@ private function configure(array $config): void
411411
$cookie['path'] . (isset($cookie['samesite']) ? '; SameSite=' . $cookie['samesite'] : ''),
412412
$cookie['domain'],
413413
$cookie['secure'],
414-
$cookie['httponly']
414+
$cookie['httponly'],
415415
);
416416
}
417417
if (session_status() === PHP_SESSION_ACTIVE) {
@@ -456,7 +456,7 @@ public function setCookieParameters(
456456
string $path,
457457
string $domain = null,
458458
bool $secure = null,
459-
string $sameSite = null
459+
string $sameSite = null,
460460
) {
461461
return $this->setOptions([
462462
'cookie_path' => $path,
@@ -515,7 +515,7 @@ private function sendCookie(): void
515515
$cookie['domain'],
516516
$cookie['secure'],
517517
$cookie['httponly'],
518-
$cookie['samesite'] ?? null
518+
$cookie['samesite'] ?? null,
519519
);
520520
}
521521
}

src/Http/Url.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,8 @@ public function canonicalize()
370370
{
371371
$this->path = preg_replace_callback(
372372
'#[^!$&\'()*+,/:;=@%]+#',
373-
function (array $m): string { return rawurlencode($m[0]); },
374-
self::unescape($this->path, '%/')
373+
fn(array $m): string => rawurlencode($m[0]),
374+
self::unescape($this->path, '%/'),
375375
);
376376
$this->host = self::idnHostToUnicode(strtolower($this->host));
377377
return $this;
@@ -423,8 +423,8 @@ public static function unescape(string $s, string $reserved = '%;/?:@&=+$,'): st
423423
if ($reserved !== '') {
424424
$s = preg_replace_callback(
425425
'#%(' . substr(chunk_split(bin2hex($reserved), 2, '|'), 0, -1) . ')#i',
426-
function (array $m): string { return '%25' . strtoupper($m[1]); },
427-
$s
426+
fn(array $m): string => '%25' . strtoupper($m[1]),
427+
$s,
428428
);
429429
}
430430
return rawurldecode($s);

tests/Http.DI/HttpExtension.csp.phpt

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,25 @@ $compiler = new DI\Compiler;
2222
$compiler->addExtension('http', new HttpExtension);
2323
$loader = new DI\Config\Loader;
2424
$config = $loader->load(Tester\FileMock::create(<<<'EOD'
25-
http:
26-
csp:
27-
default-src: "'self' https://example.com"
28-
upgrade-insecure-requests:
29-
script-src: 'nonce'
30-
style-src:
31-
- self
32-
- https://example.com
33-
- http:
34-
require-sri-for: style
35-
sandbox: allow-forms
36-
plugin-types: application/x-java-applet
37-
38-
cspReportOnly:
39-
default-src: "'nonce'"
40-
report-uri: https://example.com/report
41-
upgrade-insecure-requests: true
42-
block-all-mixed-content: false
43-
EOD
25+
http:
26+
csp:
27+
default-src: "'self' https://example.com"
28+
upgrade-insecure-requests:
29+
script-src: 'nonce'
30+
style-src:
31+
- self
32+
- https://example.com
33+
- http:
34+
require-sri-for: style
35+
sandbox: allow-forms
36+
plugin-types: application/x-java-applet
37+
38+
cspReportOnly:
39+
default-src: "'nonce'"
40+
report-uri: https://example.com/report
41+
upgrade-insecure-requests: true
42+
block-all-mixed-content: false
43+
EOD
4444
, 'neon'));
4545

4646
eval($compiler->addConfig($config)->compile());

0 commit comments

Comments
 (0)