Skip to content

Commit

Permalink
Update code to reduce redundancy and simplify readability
Browse files Browse the repository at this point in the history
  • Loading branch information
df2k2 committed Jun 8, 2020
1 parent b3d318d commit 01309d8
Showing 1 changed file with 11 additions and 26 deletions.
37 changes: 11 additions & 26 deletions lib/internal/Magento/Framework/App/Request/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,8 @@ public function isDirectAccessFrontendName($code)
*/
public function getBasePath()
{
$path = parent::getBasePath();
if (empty($path)) {
$path = '/';
} else {
$path = str_replace('\\', '/', $path);
}
return $path;
return empty(parent::getBasePath()) ? '/'
: str_replace('\\', '/', parent::getBasePath());
}

/**
Expand All @@ -228,8 +223,7 @@ public function getFrontName()
public function setRouteName($route)
{
$this->route = $route;
$module = $this->routeConfig->getRouteFrontName($route);
if ($module) {
if ($module = $this->routeConfig->getRouteFrontName($route)) {
$this->setModuleName($module);
}
return $this;
Expand Down Expand Up @@ -292,13 +286,11 @@ public function initForward()
* If passed name will be null whole state array will be returned.
*
* @param string $name
* @return array|string|null
* @return mixed|null
*/
public function getBeforeForwardInfo($name = null)
{
if ($name === null) {
return $this->beforeForwardInfo;
} elseif (isset($this->beforeForwardInfo[$name])) {
if ($name !== null && isset($this->beforeForwardInfo[$name])) {
return $this->beforeForwardInfo[$name];
}
return null;
Expand All @@ -311,13 +303,9 @@ public function getBeforeForwardInfo($name = null)
*/
public function isAjax()
{
if ($this->isXmlHttpRequest()) {
return true;
}
if ($this->getParam('ajax') || $this->getParam('isAjax')) {
return true;
}
return false;
return $this->isXmlHttpRequest()
|| $this->getParam('ajax', null)
|| $this->getParam('isAjax', null);
}

/**
Expand Down Expand Up @@ -365,7 +353,7 @@ public static function getDistroBaseUrlPath($server)
$result = '';
if (isset($server['SCRIPT_NAME'])) {
$envPath = str_replace('\\', '/', dirname(str_replace('\\', '/', $server['SCRIPT_NAME'])));
if ($envPath != '.' && $envPath != '/') {
if ($envPath !== '.' && $envPath !== '/') {
$result = $envPath;
}
}
Expand Down Expand Up @@ -425,11 +413,8 @@ public function __sleep()
public function isSafeMethod()
{
if ($this->isSafeMethod === null) {
if (isset($_SERVER['REQUEST_METHOD']) && (in_array($_SERVER['REQUEST_METHOD'], $this->safeRequestTypes))) {
$this->isSafeMethod = true;
} else {
$this->isSafeMethod = false;
}
$this->isSafeMethod = isset($_SERVER['REQUEST_METHOD'])
&& (in_array($_SERVER['REQUEST_METHOD'], $this->safeRequestTypes));
}
return $this->isSafeMethod;
}
Expand Down

0 comments on commit 01309d8

Please sign in to comment.