Skip to content

Commit

Permalink
Merge pull request #22 from ezzatron/simplified-assertion-trimming
Browse files Browse the repository at this point in the history
Simplified assertion exception stack trace trimming.
  • Loading branch information
ezzatron committed Sep 20, 2016
2 parents a03b1eb + 05e75a7 commit 6bbd382
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 22 deletions.
2 changes: 1 addition & 1 deletion specs/responder/exception/assertion-exception.spec.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

describe('AssertionException', function() {
describe('::trim()', function() {
xit('handles traces without a Leo call', function() {
it('handles traces without a Leo call', function() {
$exception = new Exception();
AssertionException::trim($exception);
expect(count($exception->getTrace()))->to->equal(0);
Expand Down
29 changes: 8 additions & 21 deletions src/Responder/Exception/AssertionException.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,32 +60,19 @@ public static function traceLeoCall(array $trace)
{
$prefix = 'Peridot\\Leo\\';

$index = null;
$broke = false;
for ($i = count($trace) - 1; $i >= 0; --$i) {
$entry = $trace[$i];

foreach ($trace as $index => $call) {
if (isset($call['class'])) {
if (0 !== strpos($call['class'], $prefix)) {
$broke = true;

break;
if (isset($entry['class'])) {
if (0 === strpos($entry['class'], $prefix)) {
return $entry;
}
} elseif (0 !== strpos($call['function'], $prefix)) {
$broke = true;

break;
} elseif (0 === strpos($entry['function'], $prefix)) {
return $entry;
}
}

if (null === $index) {
return;
}

if (!$broke) {
++$index;
}

return $trace[$index - 1];
return null;
}

/**
Expand Down

0 comments on commit 6bbd382

Please sign in to comment.