Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Clockwork/DataSource/EloquentDataSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ protected function quoteBinding($binding, $connection)
// Increment query counts for collected query
protected function incrementQueryCount($query)
{
$sql = ltrim($query['query']);
$sql = ltrim($query['query'] ?? '');

$this->count['total']++;

Expand Down
6 changes: 3 additions & 3 deletions Clockwork/DataSource/LumenDataSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ protected function getRequestMethod()
if ($this->app->bound('request')) {
return $this->app['request']->getMethod();
} elseif (isset($_POST['_method'])) {
return strtoupper($_POST['_method']);
return strtoupper((string) $_POST['_method']);
} else {
return $_SERVER['REQUEST_METHOD'];
return $_SERVER['REQUEST_METHOD'] ?? null;
}
}

Expand Down Expand Up @@ -188,7 +188,7 @@ protected function getPathInfo()
return $this->app['request']->getPathInfo();
} else {
$query = $_SERVER['QUERY_STRING'] ?? '';
return '/' . trim(str_replace("?{$query}", '', $_SERVER['REQUEST_URI']), '/');
return '/' . trim(str_replace("?{$query}", '', $_SERVER['REQUEST_URI'] ?? ''), '/');
}
}
}
2 changes: 1 addition & 1 deletion Clockwork/DataSource/PhpDataSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ protected function getRequestUrl()
$port = (! $https && $port != 80 || $https && $port != 443) ? ":{$port}" : '';

// remove port number from the host
$host = $host ? preg_replace('/:\d+$/', '', trim($host)) : null;
$host = $host !== null ? preg_replace('/:\d+$/', '', trim($host)) : null;

return "{$scheme}://{$host}{$port}{$uri}";
}
Expand Down
16 changes: 8 additions & 8 deletions Clockwork/Helpers/StackFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,24 +101,24 @@ public function closure()

protected function matchesClass(StackFrame $frame)
{
if (count($this->classes) && ! in_array($frame->class, $this->classes)) return false;
if (count($this->notClasses) && in_array($frame->class, $this->notClasses)) return false;
if (count($this->classes) && ! in_array($frame->class ?? '', $this->classes)) return false;
if (count($this->notClasses) && in_array($frame->class ?? '', $this->notClasses)) return false;

return true;
}

protected function matchesFile(StackFrame $frame)
{
if (count($this->files) && ! in_array($frame->file, $this->files)) return false;
if (count($this->notFiles) && in_array($frame->file, $this->notFiles)) return false;
if (count($this->files) && ! in_array($frame->file ?? '', $this->files)) return false;
if (count($this->notFiles) && in_array($frame->file ?? '', $this->notFiles)) return false;

return true;
}

protected function matchesFunction(StackFrame $frame)
{
if (count($this->functions) && ! in_array($frame->function, $this->functions)) return false;
if (count($this->notFunctions) && in_array($frame->function, $this->notFunctions)) return false;
if (count($this->functions) && ! in_array($frame->function ?? '', $this->functions)) return false;
if (count($this->notFunctions) && in_array($frame->function ?? '', $this->notFunctions)) return false;

return true;
}
Expand All @@ -140,8 +140,8 @@ protected function matchesNamespace(StackFrame $frame)

protected function matchesVendor(StackFrame $frame)
{
if (count($this->vendors) && ! in_array($frame->vendor, $this->vendors)) return false;
if (count($this->notVendors) && in_array($frame->vendor, $this->notVendors)) return false;
if (count($this->vendors) && ! in_array($frame->vendor ?? '', $this->vendors)) return false;
if (count($this->notVendors) && in_array($frame->vendor ?? '', $this->notVendors)) return false;

return true;
}
Expand Down
2 changes: 1 addition & 1 deletion Clockwork/Request/IncomingRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function input($key, $default = null)
// Returns true, if HTTP host is one of the common domains used for local development
public function hasLocalHost()
{
$segments = explode('.', $this->host);
$segments = explode('.', $this->host ?? '');
$tld = $segments[count($segments) - 1];

return $this->host == '127.0.0.1'
Expand Down
10 changes: 5 additions & 5 deletions Clockwork/Request/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -569,39 +569,39 @@ public function getDatabaseSlowQueriesCount()
public function getDatabaseSelects()
{
return count(array_filter($this->databaseQueries, function ($query) {
return preg_match('/^select\b/i', ltrim($query['query']));
return preg_match('/^select\b/i', ltrim($query['query'] ?? ''));
}));
}

// Compute total database insert queries count
public function getDatabaseInserts()
{
return count(array_filter($this->databaseQueries, function ($query) {
return preg_match('/^insert\b/i', ltrim($query['query']));
return preg_match('/^insert\b/i', ltrim($query['query'] ?? ''));
}));
}

// Compute total database update queries count
public function getDatabaseUpdates()
{
return count(array_filter($this->databaseQueries, function ($query) {
return preg_match('/^update\b/i', ltrim($query['query']));
return preg_match('/^update\b/i', ltrim($query['query'] ?? ''));
}));
}

// Compute total database delete queries count
public function getDatabaseDeletes()
{
return count(array_filter($this->databaseQueries, function ($query) {
return preg_match('/^delete\b/i', ltrim($query['query']));
return preg_match('/^delete\b/i', ltrim($query['query'] ?? ''));
}));
}

// Compute total database other queries count
public function getDatabaseOthers()
{
return count(array_filter($this->databaseQueries, function ($query) {
return ! preg_match('/^(select|insert|update|delete)\b/i', ltrim($query['query']));
return ! preg_match('/^(select|insert|update|delete)\b/i', ltrim($query['query'] ?? ''));
}));
}

Expand Down
6 changes: 3 additions & 3 deletions Clockwork/Request/ShouldCollect.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ protected function passExcept(IncomingRequest $request)
if (! count($this->except)) return true;

foreach ($this->except as $pattern) {
if (preg_match('#' . str_replace('#', '\#', $pattern) . '#', $request->uri)) return false;
if (preg_match('#' . str_replace('#', '\#', $pattern) . '#', $request->uri ?? '')) return false;
}

return true;
Expand All @@ -89,7 +89,7 @@ protected function passOnly(IncomingRequest $request)
if (! count($this->only)) return true;

foreach ($this->only as $pattern) {
if (preg_match('#' . str_replace('#', '\#', $pattern) . '#', $request->uri)) return true;
if (preg_match('#' . str_replace('#', '\#', $pattern) . '#', $request->uri ?? '')) return true;
}

return false;
Expand All @@ -99,7 +99,7 @@ protected function passExceptPreflight(IncomingRequest $request)
{
if (! $this->exceptPreflight) return true;

return strtoupper($request->method) != 'OPTIONS';
return strtoupper($request->method ?? '') != 'OPTIONS';
}

protected function passCallback(IncomingRequest $request)
Expand Down
8 changes: 5 additions & 3 deletions Clockwork/Support/Vanilla/Clockwork.php
Original file line number Diff line number Diff line change
Expand Up @@ -497,13 +497,15 @@ protected function incomingRequest()
// Creates an incoming request instance from globals
protected function incomingRequestFromGlobals()
{
$host = $_SERVER['HTTP_HOST'] ?? $_SERVER['SERVER_NAME'] ?? $_SERVER['SERVER_ADDR'] ?? '';

return new IncomingRequest([
'method' => $_SERVER['REQUEST_METHOD'],
'uri' => $_SERVER['REQUEST_URI'],
'method' => $_SERVER['REQUEST_METHOD'] ?? null,
'uri' => $_SERVER['REQUEST_URI'] ?? null,
'headers' => $_SERVER,
'input' => array_merge($_GET, $_POST, (array) json_decode(file_get_contents('php://input'), true)),
'cookies' => $_COOKIE,
'host' => explode(':', $_SERVER['HTTP_HOST'] ?: $_SERVER['SERVER_NAME'] ?: $_SERVER['SERVER_ADDR'])[0]
'host' => explode(':', $host)[0]
]);
}

Expand Down