Skip to content

Commit c9ca94f

Browse files
committed
cs
1 parent c557f21 commit c9ca94f

File tree

10 files changed

+35
-34
lines changed

10 files changed

+35
-34
lines changed

src/Bridges/HttpDI/HttpExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public function loadConfiguration(): void
9393
private function sendHeaders(): void
9494
{
9595
$config = $this->config;
96-
$headers = array_map('strval', $config->headers);
96+
$headers = array_map(strval(...), $config->headers);
9797

9898
if (isset($config->frames) && $config->frames !== true && !isset($headers['X-Frame-Options'])) {
9999
$frames = $config->frames;

src/Http/FileUpload.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public function getSuggestedExtension(): ?string
140140
}
141141
[, , $type] = Nette\Utils\Helpers::falseToNull(@getimagesize($this->tmpName)); // @ - files smaller than 12 bytes causes read error
142142
if ($type) {
143-
return $this->extension = image_type_to_extension($type, false);
143+
return $this->extension = image_type_to_extension($type, include_dot: false);
144144
}
145145
$this->extension = false;
146146
}
@@ -231,7 +231,7 @@ function (string $message) use ($dest): void {
231231
*/
232232
public function isImage(): bool
233233
{
234-
$types = array_map(fn($type) => Image::typeToMimeType($type), Image::getSupportedTypes());
234+
$types = array_map(Image::typeToMimeType(...), Image::getSupportedTypes());
235235
return in_array($this->getContentType(), $types, strict: true);
236236
}
237237

src/Http/Helpers.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public static function ipMatch(string $ip, string $mask): bool
5656
}
5757

5858

59-
public static function initCookie(IRequest $request, IResponse $response)
59+
public static function initCookie(IRequest $request, IResponse $response): void
6060
{
6161
$response->setCookie(self::StrictCookieName, '1', 0, '/', sameSite: IResponse::SameSiteStrict);
6262
}

src/Http/Request.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class Request implements IRequest
3535
{
3636
use Nette\SmartObject;
3737

38+
/** @var string[] */
3839
private readonly array $headers;
3940

4041
private readonly ?\Closure $rawBodyCallback;
@@ -178,6 +179,7 @@ public function getHeader(string $header): ?string
178179

179180
/**
180181
* Returns all HTTP headers as associative array.
182+
* @return string[]
181183
*/
182184
public function getHeaders(): array
183185
{
@@ -207,7 +209,7 @@ public function getOrigin(): ?UrlImmutable
207209
return $header === 'null'
208210
? null
209211
: new UrlImmutable($header);
210-
} catch (Nette\InvalidArgumentException $e) {
212+
} catch (Nette\InvalidArgumentException) {
211213
return null;
212214
}
213215
}

src/Http/RequestFactory.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class RequestFactory
2424
/** @internal */
2525
private const ValidChars = '\x09\x0A\x0D\x20-\x7E\xA0-\x{10FFFF}';
2626

27+
/** @var array<string, string[]> */
2728
public array $urlFilters = [
2829
'path' => ['#//#' => '/'], // '%20' => ''
2930
'url' => [], // '#[.,)]$#D' => ''
@@ -132,7 +133,7 @@ private function getScriptPath(Url $url): string
132133

133134
private function getGetPostCookie(Url $url): array
134135
{
135-
$useFilter = (!in_array((string) ini_get('filter.default'), ['', 'unsafe_raw'], true) || ini_get('filter.default_flags'));
136+
$useFilter = (!in_array((string) ini_get('filter.default'), ['', 'unsafe_raw'], strict: true) || ini_get('filter.default_flags'));
136137

137138
$query = $url->getQueryParameters();
138139
$post = $useFilter
@@ -235,7 +236,7 @@ private function getHeaders(): array
235236
} else {
236237
$headers = [];
237238
foreach ($_SERVER as $k => $v) {
238-
if (strncmp($k, 'HTTP_', 5) === 0) {
239+
if (str_starts_with($k, 'HTTP_')) {
239240
$k = substr($k, 5);
240241
} elseif (strncmp($k, 'CONTENT_', 8)) {
241242
continue;

src/Http/Response.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ private function checkHeaders(): void
276276
} elseif (
277277
$this->warnOnBuffer &&
278278
ob_get_length() &&
279-
!array_filter(ob_get_status(true), fn(array $i): bool => !$i['chunk_size'])
279+
!array_filter(ob_get_status(full_status: true), fn(array $i): bool => !$i['chunk_size'])
280280
) {
281281
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.');
282282
}

src/Http/Session.php

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,16 @@ class Session
4646
'cookie_lifetime' => 0, // for a maximum of 3 hours or until the browser is closed
4747
'gc_maxlifetime' => self::DefaultFileLifetime, // 3 hours
4848
];
49-
50-
private readonly IRequest $request;
51-
private readonly IResponse $response;
5249
private ?\SessionHandlerInterface $handler = null;
5350
private bool $readAndClose = false;
5451
private bool $fileExists = true;
5552
private bool $autoStart = true;
5653

5754

58-
public function __construct(IRequest $request, IResponse $response)
59-
{
60-
$this->request = $request;
61-
$this->response = $response;
55+
public function __construct(
56+
private readonly IRequest $request,
57+
private readonly IResponse $response,
58+
) {
6259
$this->options['cookie_path'] = &$this->response->cookiePath;
6360
$this->options['cookie_domain'] = &$this->response->cookieDomain;
6461
$this->options['cookie_secure'] = &$this->response->cookieSecure;
@@ -75,7 +72,7 @@ public function start(): void
7572
}
7673

7774

78-
private function doStart($mustExists = false): void
75+
private function doStart(bool $mustExists = false): void
7976
{
8077
if (session_status() === PHP_SESSION_ACTIVE) { // adapt an existing session
8178
if (!$this->started) {
@@ -254,7 +251,7 @@ public function regenerateId(): void
254251
throw new Nette\InvalidStateException('Cannot regenerate session ID after HTTP headers have been sent' . ($file ? " (output started at $file:$line)." : '.'));
255252
}
256253

257-
session_regenerate_id(true);
254+
session_regenerate_id(delete_old_session: true);
258255
} else {
259256
session_id(session_create_id());
260257
}
@@ -318,7 +315,7 @@ public function getSection(string $section, string $class = SessionSection::clas
318315
public function hasSection(string $section): bool
319316
{
320317
if ($this->exists() && !$this->started) {
321-
$this->autoStart(false);
318+
$this->autoStart(forWrite: false);
322319
}
323320

324321
return !empty($_SESSION['__NF']['DATA'][$section]);
@@ -329,7 +326,7 @@ public function hasSection(string $section): bool
329326
public function getSectionNames(): array
330327
{
331328
if ($this->exists() && !$this->started) {
332-
$this->autoStart(false);
329+
$this->autoStart(forWrite: false);
333330
}
334331

335332
return array_keys($_SESSION['__NF']['DATA'] ?? []);
@@ -442,7 +439,7 @@ private function configure(array $config): void
442439
if ($value === null || ini_get("session.$key") == $value) { // intentionally ==
443440
continue;
444441

445-
} elseif (strncmp($key, 'cookie_', 7) === 0) {
442+
} elseif (str_starts_with($key, 'cookie_')) {
446443
$cookie[substr($key, 7)] = $value;
447444

448445
} else {

src/Http/SessionSection.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function __construct(
3636
*/
3737
public function getIterator(): \Iterator
3838
{
39-
$this->session->autoStart(false);
39+
$this->session->autoStart(forWrite: false);
4040
return new \ArrayIterator($this->getData() ?? []);
4141
}
4242

@@ -49,7 +49,7 @@ public function set(string $name, mixed $value, ?string $expire = null): void
4949
if ($value === null) {
5050
$this->remove($name);
5151
} else {
52-
$this->session->autoStart(true);
52+
$this->session->autoStart(forWrite: true);
5353
$this->getData()[$name] = $value;
5454
$this->setExpiration($expire, $name);
5555
}
@@ -65,7 +65,7 @@ public function get(string $name): mixed
6565
throw new \ArgumentCountError(__METHOD__ . '() expects 1 arguments, given more.');
6666
}
6767

68-
$this->session->autoStart(false);
68+
$this->session->autoStart(forWrite: false);
6969
return $this->getData()[$name] ?? null;
7070
}
7171

@@ -76,7 +76,7 @@ public function get(string $name): mixed
7676
*/
7777
public function remove(string|array|null $name = null): void
7878
{
79-
$this->session->autoStart(false);
79+
$this->session->autoStart(forWrite: false);
8080
if (func_num_args() > 1) {
8181
throw new \ArgumentCountError(__METHOD__ . '() expects at most 1 arguments, given more.');
8282

@@ -96,9 +96,9 @@ public function remove(string|array|null $name = null): void
9696
* Sets a variable in this session section.
9797
* @deprecated use set() instead
9898
*/
99-
public function __set(string $name, $value): void
99+
public function __set(string $name, mixed $value): void
100100
{
101-
$this->session->autoStart(true);
101+
$this->session->autoStart(forWrite: true);
102102
$this->getData()[$name] = $value;
103103
}
104104

@@ -109,7 +109,7 @@ public function __set(string $name, $value): void
109109
*/
110110
public function &__get(string $name): mixed
111111
{
112-
$this->session->autoStart(true);
112+
$this->session->autoStart(forWrite: true);
113113
$data = &$this->getData();
114114
if ($this->warnOnUndefined && !array_key_exists($name, $data ?? [])) {
115115
trigger_error("The variable '$name' does not exist in session section");
@@ -125,7 +125,7 @@ public function &__get(string $name): mixed
125125
*/
126126
public function __isset(string $name): bool
127127
{
128-
$this->session->autoStart(false);
128+
$this->session->autoStart(forWrite: false);
129129
return isset($this->getData()[$name]);
130130
}
131131

src/Http/Url.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class Url implements \JsonSerializable
4747
{
4848
use Nette\SmartObject;
4949

50+
/** @var array<string, int> */
5051
public static array $defaultPorts = [
5152
'http' => 80,
5253
'https' => 443,

src/Http/UserStorage.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function __construct(
3737
*/
3838
public function setAuthenticated(bool $state): self
3939
{
40-
$section = $this->getSessionSection(true);
40+
$section = $this->getSessionSection(need: true);
4141
$section->authenticated = $state;
4242

4343
// Session Fixation defence
@@ -61,7 +61,7 @@ public function setAuthenticated(bool $state): self
6161
*/
6262
public function isAuthenticated(): bool
6363
{
64-
$session = $this->getSessionSection(false);
64+
$session = $this->getSessionSection(need: false);
6565
return $session && $session->authenticated;
6666
}
6767

@@ -71,7 +71,7 @@ public function isAuthenticated(): bool
7171
*/
7272
public function setIdentity(?IIdentity $identity): self
7373
{
74-
$this->getSessionSection(true)->identity = $identity;
74+
$this->getSessionSection(need: true)->identity = $identity;
7575
return $this;
7676
}
7777

@@ -81,7 +81,7 @@ public function setIdentity(?IIdentity $identity): self
8181
*/
8282
public function getIdentity(): ?Nette\Security\IIdentity
8383
{
84-
$session = $this->getSessionSection(false);
84+
$session = $this->getSessionSection(need: false);
8585
return $session ? $session->identity : null;
8686
}
8787

@@ -114,7 +114,7 @@ public function getNamespace(): string
114114
*/
115115
public function setExpiration(?string $time, int $flags = 0): self
116116
{
117-
$section = $this->getSessionSection(true);
117+
$section = $this->getSessionSection(need: true);
118118
if ($time) {
119119
$time = Nette\Utils\DateTime::from($time)->format('U');
120120
$section->expireTime = $time;
@@ -135,7 +135,7 @@ public function setExpiration(?string $time, int $flags = 0): self
135135
*/
136136
public function getLogoutReason(): ?int
137137
{
138-
$session = $this->getSessionSection(false);
138+
$session = $this->getSessionSection(need: false);
139139
return $session ? $session->reason : null;
140140
}
141141

0 commit comments

Comments
 (0)