Skip to content

Commit 4be7cde

Browse files
committed
simplified code
1 parent 7ff93fc commit 4be7cde

File tree

5 files changed

+21
-47
lines changed

5 files changed

+21
-47
lines changed

src/Http/RequestFactory.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ private function getScriptPath(Url $url): string
120120
{
121121
$path = $url->getPath();
122122
$lpath = strtolower($path);
123-
$script = isset($_SERVER['SCRIPT_NAME']) ? strtolower($_SERVER['SCRIPT_NAME']) : '';
123+
$script = strtolower($_SERVER['SCRIPT_NAME'] ?? '');
124124
if ($lpath !== $script) {
125125
$max = min(strlen($lpath), strlen($script));
126126
for ($i = 0; $i < $max && $lpath[$i] === $script[$i]; $i++);
@@ -238,8 +238,7 @@ private function getMethod(): ?string
238238
$method = $_SERVER['REQUEST_METHOD'] ?? null;
239239
if (
240240
$method === 'POST'
241-
&& isset($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'])
242-
&& preg_match('#^[A-Z]+\z#', $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'])
241+
&& preg_match('#^[A-Z]+\z#', $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] ?? '')
243242
) {
244243
$method = $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'];
245244
}

src/Http/Response.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,7 @@ public function __destruct()
230230
{
231231
if (
232232
self::$fixIE
233-
&& isset($_SERVER['HTTP_USER_AGENT'])
234-
&& strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE ') !== false
233+
&& strpos($_SERVER['HTTP_USER_AGENT'] ?? '', 'MSIE ') !== false
235234
&& in_array($this->code, [400, 403, 404, 405, 406, 408, 409, 410, 500, 501, 505], true)
236235
&& preg_match('#^text/html(?:;|$)#', (string) $this->getHeader('Content-Type'))
237236
) {

src/Http/Session.php

+13-33
Original file line numberDiff line numberDiff line change
@@ -128,21 +128,16 @@ private function initialize(): void
128128
}
129129
}
130130

131-
// process meta metadata
132-
if (isset($nf['META'])) {
133-
$now = time();
134-
// expire section variables
135-
foreach ($nf['META'] as $section => $metadata) {
136-
if (is_array($metadata)) {
137-
foreach ($metadata as $variable => $value) {
138-
if (!empty($value['T']) && $now > $value['T']) {
139-
if ($variable === '') { // expire whole section
140-
unset($nf['META'][$section], $nf['DATA'][$section]);
141-
continue 2;
142-
}
143-
unset($nf['META'][$section][$variable], $nf['DATA'][$section][$variable]);
144-
}
131+
// expire section variables
132+
$now = time();
133+
foreach ($nf['META'] ?? [] as $section => $metadata) {
134+
foreach ($metadata ?? [] as $variable => $value) {
135+
if (!empty($value['T']) && $now > $value['T']) {
136+
if ($variable === '') { // expire whole section
137+
unset($nf['META'][$section], $nf['DATA'][$section]);
138+
continue 2;
145139
}
140+
unset($nf['META'][$section][$variable], $nf['DATA'][$section][$variable]);
146141
}
147142
}
148143
}
@@ -292,12 +287,7 @@ public function getIterator(): \Iterator
292287
$this->start();
293288
}
294289

295-
if (isset($_SESSION['__NF']['DATA'])) {
296-
return new \ArrayIterator(array_keys($_SESSION['__NF']['DATA']));
297-
298-
} else {
299-
return new \ArrayIterator;
300-
}
290+
return new \ArrayIterator(array_keys($_SESSION['__NF']['DATA'] ?? []));
301291
}
302292

303293

@@ -312,21 +302,11 @@ public function clean(): void
312302
}
313303

314304
$nf = &$_SESSION['__NF'];
315-
if (isset($nf['META']) && is_array($nf['META'])) {
316-
foreach ($nf['META'] as $name => $foo) {
317-
if (empty($nf['META'][$name])) {
318-
unset($nf['META'][$name]);
319-
}
305+
foreach ($nf['META'] ?? [] as $name => $foo) {
306+
if (empty($nf['META'][$name])) {
307+
unset($nf['META'][$name]);
320308
}
321309
}
322-
323-
if (empty($nf['META'])) {
324-
unset($nf['META']);
325-
}
326-
327-
if (empty($nf['DATA'])) {
328-
unset($nf['DATA']);
329-
}
330310
}
331311

332312

src/Http/SessionSection.php

+1-5
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,7 @@ private function start(): void
6161
public function getIterator(): \Iterator
6262
{
6363
$this->start();
64-
if (isset($this->data)) {
65-
return new \ArrayIterator($this->data);
66-
} else {
67-
return new \ArrayIterator;
68-
}
64+
return new \ArrayIterator($this->data ?? []);
6965
}
7066

7167

src/Http/Url.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,12 @@ public function __construct($url = null)
9191

9292
$this->scheme = $p['scheme'] ?? '';
9393
$this->port = $p['port'] ?? null;
94-
$this->host = isset($p['host']) ? rawurldecode($p['host']) : '';
95-
$this->user = isset($p['user']) ? rawurldecode($p['user']) : '';
96-
$this->password = isset($p['pass']) ? rawurldecode($p['pass']) : '';
94+
$this->host = rawurldecode($p['host'] ?? '');
95+
$this->user = rawurldecode($p['user'] ?? '');
96+
$this->password = rawurldecode($p['pass'] ?? '');
9797
$this->setPath($p['path'] ?? '');
9898
$this->setQuery($p['query'] ?? []);
99-
$this->fragment = isset($p['fragment']) ? rawurldecode($p['fragment']) : '';
99+
$this->fragment = rawurldecode($p['fragment'] ?? '');
100100

101101
} elseif ($url instanceof UrlImmutable || $url instanceof self) {
102102
[$this->scheme, $this->user, $this->password, $this->host, $this->port, $this->path, $this->query, $this->fragment] = $url->export();

0 commit comments

Comments
 (0)