Skip to content

Commit 8a61f35

Browse files
committed
Merge pull request #8 from dimitrytarasov/master
Back-trace filtering improvements
2 parents 945dd33 + 10b6cee commit 8a61f35

1 file changed

Lines changed: 16 additions & 7 deletions

File tree

src/Stackify/Log/Entities/ErrorWrapper.php

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class ErrorWrapper
1212
private $sourceMethod;
1313

1414
const TYPE_STRING_EXCEPTION = 'StringException';
15-
const UNKNOWN_METHOD = '{unknown}';
15+
const TRACE_UNKNOWN_ITEM = '{unknown}';
1616

1717
/**
1818
* @var \Stackify\Log\Entities\ErrorWrapper
@@ -89,19 +89,23 @@ private function setTrace(array $trace)
8989
if (isset($item['function'])) {
9090
$function = $item['function'] . '()';
9191
} else {
92-
$function = self::UNKNOWN_METHOD;
92+
$function = self::TRACE_UNKNOWN_ITEM;
9393
}
9494
if (isset($item['class'])) {
9595
// type is -> or :: which means dynamic or static method call
96-
$type = isset($item['type']) ? $item['type'] : '->';
96+
$type = $this->getTraceItem($item, 'type', '->');
9797
$function = $item['class'] . $type . $function;
9898
$sourceMethod = $function;
9999
} else {
100-
$sourceMethod = $item['file'] . ':' . $function;
100+
if (isset($item['file'])) {
101+
$sourceMethod = $item['file'] . ':' . $function;
102+
} else {
103+
$sourceMethod = $function;
104+
}
101105
}
102106
$result[] = array(
103-
'file' => $item['file'],
104-
'line' => $item['line'],
107+
'file' => $this->getTraceItem($item, 'file', self::TRACE_UNKNOWN_ITEM),
108+
'line' => $this->getTraceItem($item, 'line', 0),
105109
'function' => $function,
106110
);
107111
if (0 === $index) {
@@ -111,6 +115,11 @@ private function setTrace(array $trace)
111115
$this->trace = $result;
112116
}
113117

118+
private function getTraceItem($item, $keyName, $defaulValue = null)
119+
{
120+
return isset($item[$keyName]) ? $item[$keyName] : $defaulValue;
121+
}
122+
114123
private function filterTrace(array $trace)
115124
{
116125
$filtered = array();
@@ -123,7 +132,7 @@ private function filterTrace(array $trace)
123132
}
124133
foreach ($trace as $item) {
125134
// check if path starts with $excludePath
126-
if (isset($item['file']) && false === strpos($item['file'], $excludePath)) {
135+
if (!isset($item['file']) || false === strpos($item['file'], $excludePath)) {
127136
$filtered[] = $item;
128137
}
129138
}

0 commit comments

Comments
 (0)