Skip to content

Commit a420d62

Browse files
committed
utilization of operator ??
1 parent 796ecea commit a420d62

File tree

5 files changed

+16
-16
lines changed

5 files changed

+16
-16
lines changed

src/Http/Request.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public function getPost($key = NULL, $default = NULL)
138138
*/
139139
public function getFile($key)
140140
{
141-
return isset($this->files[$key]) ? $this->files[$key] : NULL;
141+
return $this->files[$key] ?? NULL;
142142
}
143143

144144

@@ -160,7 +160,7 @@ public function getFiles()
160160
*/
161161
public function getCookie($key, $default = NULL)
162162
{
163-
return isset($this->cookies[$key]) ? $this->cookies[$key] : $default;
163+
return $this->cookies[$key] ?? $default;
164164
}
165165

166166

@@ -208,7 +208,7 @@ public function isMethod($method)
208208
public function getHeader($header, $default = NULL)
209209
{
210210
$header = strtolower($header);
211-
return isset($this->headers[$header]) ? $this->headers[$header] : $default;
211+
return $this->headers[$header] ?? $default;
212212
}
213213

214214

src/Http/RequestFactory.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ public function createHttpRequest()
6767
// DETECTS URI, base path and script path of the request.
6868
$url = new UrlScript;
6969
$url->setScheme(!empty($_SERVER['HTTPS']) && strcasecmp($_SERVER['HTTPS'], 'off') ? 'https' : 'http');
70-
$url->setUser(isset($_SERVER['PHP_AUTH_USER']) ? $_SERVER['PHP_AUTH_USER'] : '');
71-
$url->setPassword(isset($_SERVER['PHP_AUTH_PW']) ? $_SERVER['PHP_AUTH_PW'] : '');
70+
$url->setUser($_SERVER['PHP_AUTH_USER'] ?? '');
71+
$url->setPassword($_SERVER['PHP_AUTH_PW'] ?? '');
7272

7373
// host & port
7474
if ((isset($_SERVER[$tmp = 'HTTP_HOST']) || isset($_SERVER[$tmp = 'SERVER_NAME']))
@@ -83,14 +83,14 @@ public function createHttpRequest()
8383
}
8484

8585
// path & query
86-
$requestUrl = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '/';
86+
$requestUrl = $_SERVER['REQUEST_URI'] ?? '/';
8787
$requestUrl = preg_replace('#^\w++://[^/]++#', '', $requestUrl);
8888
$requestUrl = Strings::replace($requestUrl, $this->urlFilters['url']);
8989
$tmp = explode('?', $requestUrl, 2);
9090
$path = Url::unescape($tmp[0], '%/?#');
9191
$path = Strings::fixEncoding(Strings::replace($path, $this->urlFilters['path']));
9292
$url->setPath($path);
93-
$url->setQuery(isset($tmp[1]) ? $tmp[1] : '');
93+
$url->setQuery($tmp[1] ?? '');
9494

9595
// detect script path
9696
$lpath = strtolower($path);
@@ -266,7 +266,7 @@ public function createHttpRequest()
266266
}
267267

268268
// method, eg. GET, PUT, ...
269-
$method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : NULL;
269+
$method = $_SERVER['REQUEST_METHOD'] ?? NULL;
270270
if ($method === 'POST' && isset($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'])
271271
&& preg_match('#^[A-Z]+\z#', $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'])
272272
) {

src/Http/Response.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function setCode($code, $reason = NULL)
7878
500, 501, 502, 503, 504, 505, 506, 511,
7979
];
8080
if ($reason || !in_array($code, $hasReason, TRUE)) {
81-
$protocol = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1';
81+
$protocol = $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.1';
8282
header("$protocol $code " . ($reason ?: 'Unknown status'));
8383
} else {
8484
http_response_code($code);

src/Http/Session.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ public function setName($name)
258258
*/
259259
public function getName()
260260
{
261-
return isset($this->options['name']) ? $this->options['name'] : session_name();
261+
return $this->options['name'] ?? session_name();
262262
}
263263

264264

src/Http/Url.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,13 @@ public function __construct($url = NULL)
9797
throw new Nette\InvalidArgumentException("Malformed or unsupported URI '$url'.");
9898
}
9999

100-
$this->scheme = isset($p['scheme']) ? $p['scheme'] : '';
101-
$this->port = isset($p['port']) ? $p['port'] : NULL;
100+
$this->scheme = $p['scheme'] ?? '';
101+
$this->port = $p['port'] ?? NULL;
102102
$this->host = isset($p['host']) ? rawurldecode($p['host']) : '';
103103
$this->user = isset($p['user']) ? rawurldecode($p['user']) : '';
104104
$this->password = isset($p['pass']) ? rawurldecode($p['pass']) : '';
105-
$this->setPath(isset($p['path']) ? $p['path'] : '');
106-
$this->setQuery(isset($p['query']) ? $p['query'] : []);
105+
$this->setPath($p['path'] ?? '');
106+
$this->setQuery($p['query'] ?? []);
107107
$this->fragment = isset($p['fragment']) ? rawurldecode($p['fragment']) : '';
108108

109109
} elseif ($url instanceof self) {
@@ -223,7 +223,7 @@ public function getPort()
223223
{
224224
return $this->port
225225
? $this->port
226-
: (isset(self::$defaultPorts[$this->scheme]) ? self::$defaultPorts[$this->scheme] : NULL);
226+
: (self::$defaultPorts[$this->scheme] ?? NULL);
227227
}
228228

229229

@@ -304,7 +304,7 @@ public function getQueryParameters()
304304
*/
305305
public function getQueryParameter($name, $default = NULL)
306306
{
307-
return isset($this->query[$name]) ? $this->query[$name] : $default;
307+
return $this->query[$name] ?? $default;
308308
}
309309

310310

0 commit comments

Comments
 (0)