Skip to content

Commit 1e6f3d7

Browse files
authored
Merge pull request #14 from pana1990/bug/13-empty-trace
fix null access
2 parents c546ff7 + a0ed55a commit 1e6f3d7

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

src/DataCollectors/PdoDataCollector.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,27 @@ public function count(): int
5151
public function trace(): \Closure
5252
{
5353
return function (array $trace): array {
54+
$file = $trace['file'] ?? null;
55+
$line = $trace['line'] ?? null;
56+
$class = $trace['class'] ?? null;
57+
58+
if (true === isset($file, $line)) {
59+
return [
60+
'url' => sprintf($this->xdebugLinkTemplate, $file, $line),
61+
'path' => sprintf('%s:%s', $file, $line),
62+
];
63+
}
64+
65+
if (true === isset($class)) {
66+
return [
67+
'url' => null,
68+
'path' => sprintf('%s:%s', $class, $line),
69+
];
70+
}
71+
5472
return [
55-
'url' => sprintf($this->xdebugLinkTemplate, $trace['file'], $trace['line']),
56-
'path' => sprintf('%s:%s', $trace['file'], $trace['line']),
73+
'url' => null,
74+
'path' => 'Unkown',
5775
];
5876
};
5977
}

src/Resources/pages/pdo/pdo.html.twig

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
<table id="table-pdo" class="table table-bordered table-striped">
1010
<colgroup>
11-
<col />
12-
<col />
13-
<col />
11+
<col/>
12+
<col/>
13+
<col/>
1414
</colgroup>
1515
<thead>
1616
<tr>
@@ -34,7 +34,11 @@
3434
</p>
3535
<div class="collapse" id="trace-{{ index }}">
3636
{% for trace in value['trace'] %}
37-
<a href="{{ trace['url'] }}">{{ trace['path'] }}</a><br>
37+
{% if trace['url'] is not null %}
38+
<a href="{{ trace['url'] }}">{{ trace['path'] }}</a><br>
39+
{% else %}
40+
{{ trace['path'] }}<br>
41+
{% endif %}
3842
{% endfor %}
3943
</div>
4044
</div>
@@ -52,6 +56,6 @@
5256
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.6.0/highlight.min.js"></script>
5357

5458
<script>
55-
hljs.highlightAll();
59+
hljs.highlightAll();
5660
</script>
5761
{% endblock %}

0 commit comments

Comments
 (0)