Skip to content

Commit 01309d8

Browse files
authored
Update code to reduce redundancy and simplify readability
1 parent b3d318d commit 01309d8

File tree

1 file changed

+11
-26
lines changed
  • lib/internal/Magento/Framework/App/Request

1 file changed

+11
-26
lines changed

lib/internal/Magento/Framework/App/Request/Http.php

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,8 @@ public function isDirectAccessFrontendName($code)
199199
*/
200200
public function getBasePath()
201201
{
202-
$path = parent::getBasePath();
203-
if (empty($path)) {
204-
$path = '/';
205-
} else {
206-
$path = str_replace('\\', '/', $path);
207-
}
208-
return $path;
202+
return empty(parent::getBasePath()) ? '/'
203+
: str_replace('\\', '/', parent::getBasePath());
209204
}
210205

211206
/**
@@ -228,8 +223,7 @@ public function getFrontName()
228223
public function setRouteName($route)
229224
{
230225
$this->route = $route;
231-
$module = $this->routeConfig->getRouteFrontName($route);
232-
if ($module) {
226+
if ($module = $this->routeConfig->getRouteFrontName($route)) {
233227
$this->setModuleName($module);
234228
}
235229
return $this;
@@ -292,13 +286,11 @@ public function initForward()
292286
* If passed name will be null whole state array will be returned.
293287
*
294288
* @param string $name
295-
* @return array|string|null
289+
* @return mixed|null
296290
*/
297291
public function getBeforeForwardInfo($name = null)
298292
{
299-
if ($name === null) {
300-
return $this->beforeForwardInfo;
301-
} elseif (isset($this->beforeForwardInfo[$name])) {
293+
if ($name !== null && isset($this->beforeForwardInfo[$name])) {
302294
return $this->beforeForwardInfo[$name];
303295
}
304296
return null;
@@ -311,13 +303,9 @@ public function getBeforeForwardInfo($name = null)
311303
*/
312304
public function isAjax()
313305
{
314-
if ($this->isXmlHttpRequest()) {
315-
return true;
316-
}
317-
if ($this->getParam('ajax') || $this->getParam('isAjax')) {
318-
return true;
319-
}
320-
return false;
306+
return $this->isXmlHttpRequest()
307+
|| $this->getParam('ajax', null)
308+
|| $this->getParam('isAjax', null);
321309
}
322310

323311
/**
@@ -365,7 +353,7 @@ public static function getDistroBaseUrlPath($server)
365353
$result = '';
366354
if (isset($server['SCRIPT_NAME'])) {
367355
$envPath = str_replace('\\', '/', dirname(str_replace('\\', '/', $server['SCRIPT_NAME'])));
368-
if ($envPath != '.' && $envPath != '/') {
356+
if ($envPath !== '.' && $envPath !== '/') {
369357
$result = $envPath;
370358
}
371359
}
@@ -425,11 +413,8 @@ public function __sleep()
425413
public function isSafeMethod()
426414
{
427415
if ($this->isSafeMethod === null) {
428-
if (isset($_SERVER['REQUEST_METHOD']) && (in_array($_SERVER['REQUEST_METHOD'], $this->safeRequestTypes))) {
429-
$this->isSafeMethod = true;
430-
} else {
431-
$this->isSafeMethod = false;
432-
}
416+
$this->isSafeMethod = isset($_SERVER['REQUEST_METHOD'])
417+
&& (in_array($_SERVER['REQUEST_METHOD'], $this->safeRequestTypes));
433418
}
434419
return $this->isSafeMethod;
435420
}

0 commit comments

Comments
 (0)