Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update code to reduce redundancy and simplify readability #28608

Merged
merged 8 commits into from
Aug 8, 2020
26 changes: 8 additions & 18 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());
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If 'parent: getBasePath()' is not empty, we will call 'parent::getBasePath()' again.
I think it is better to use the $ path variable.


/**
Expand Down Expand Up @@ -298,10 +293,9 @@ public function getBeforeForwardInfo($name = null)
{
if ($name === null) {
return $this->beforeForwardInfo;
} elseif (isset($this->beforeForwardInfo[$name])) {
return $this->beforeForwardInfo[$name];
}
return null;

return $this->beforeForwardInfo[$name] ?? null;
}

/**
Expand All @@ -311,13 +305,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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default value is null, you do not need to provide it explicitly

\Magento\Framework\App\Request\Http\Proxy::getParam($key, $default = null)

}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$this->getParam('ajax', null), second parameter is not required


/**
Expand Down Expand Up @@ -365,7 +355,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