Skip to content

Commit

Permalink
remove getServerURLandRequestURI() function as used only once at Logg…
Browse files Browse the repository at this point in the history
…ing class
  • Loading branch information
samsonasik committed May 25, 2018
1 parent ac091d7 commit b7fe27b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 25 deletions.
20 changes: 12 additions & 8 deletions src/Handler/Logging.php
Expand Up @@ -20,8 +20,6 @@
use Zend\Psr7Bridge\Psr7ServerRequest;
use Zend\Stdlib\RequestInterface;

use function ErrorHeroModule\getServerURLandRequestURI;

class Logging
{
/**
Expand Down Expand Up @@ -180,16 +178,22 @@ private function collectErrorExceptionData(Throwable $t) : array

private function collectErrorExceptionExtraData(array $collectedExceptionData) : array
{
if ($this->request instanceof ConsoleRequest) {
$request = $this->request;
if ($request instanceof ConsoleRequest) {
$this->serverUrl = \php_uname('n');
$requestUri = ':' . \basename((string) \getcwd())
. ' ' . \get_current_user()
. '$ php ' . $this->request->getScriptName() . ' ' . $this->request->toString();
. '$ php ' . $request->getScriptName() . ' ' . $request->toString();
} else {
Assertion::isInstanceOf($this->request, HttpRequest::class);
$getServerURLandRequestURI = getServerURLandRequestURI($this->request);
$this->serverUrl = $getServerURLandRequestURI['serverUrl'];
$requestUri = $getServerURLandRequestURI['requestUri'];
Assertion::isInstanceOf($request, HttpRequest::class);

$uri = $request->getUri();
$this->serverUrl = $uri->getScheme() . '://' . $uri->getHost();
$port = $uri->getPort();
if ($port !== 80) {
$this->serverUrl .= ':' . $port;
}
$requestUri = $request->getRequestUri();
}

return [
Expand Down
17 changes: 0 additions & 17 deletions src/HeroFunction.php
Expand Up @@ -5,27 +5,10 @@
namespace ErrorHeroModule;

use Seld\JsonLint\JsonParser;
use Zend\Http\PhpEnvironment\Request;

function detectAjaxMessageContentType(string $message) : string
{
return (new JsonParser())->lint($message) === null
? 'application/problem+json'
: ((\strip_tags($message) === $message) ? 'text/plain' : 'text/html');
}

function getServerURLandRequestURI(Request $request) : array
{
$uri = $request->getUri();
$serverUrl = $uri->getScheme() . '://' . $uri->getHost();
$port = $uri->getPort();
if ($port !== 80) {
$serverUrl .= ':' . $port;
}
$requestUri = $request->getRequestUri();

return [
'serverUrl' => $serverUrl,
'requestUri' => $requestUri,
];
}

0 comments on commit b7fe27b

Please sign in to comment.