Skip to content

Commit 928744d

Browse files
committed
Moved debugging output to IdentifiedGeneratorInStack
1 parent ca3da0e commit 928744d

File tree

2 files changed

+31
-17
lines changed

2 files changed

+31
-17
lines changed

src/Analyser/Generator/GeneratorNodeScopeResolver.php

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
use function get_class;
2424
use function get_debug_type;
2525
use function implode;
26-
use function is_array;
2726
use function sprintf;
2827

2928
/**
@@ -134,25 +133,12 @@ private function processStmtNodes(
134133
} catch (Throwable $e) {
135134
$stackTrace = [];
136135
foreach (array_merge($stack, [$gen]) as $identifiedGenerator) {
137-
if ($identifiedGenerator->file === null && $identifiedGenerator->line === null) {
138-
continue;
139-
}
140-
if (is_array($identifiedGenerator->node)) {
141-
$stackTrace[] = sprintf(
142-
"Stmts\n -> %s on line %d",
143-
$identifiedGenerator->file,
144-
$identifiedGenerator->line,
145-
);
136+
$string = (string) $identifiedGenerator;
137+
if ($string === '') {
146138
continue;
147139
}
148140

149-
$stackTrace[] = sprintf(
150-
"%s:%d\n -> %s on line %d",
151-
$identifiedGenerator->file,
152-
$identifiedGenerator->line,
153-
get_class($identifiedGenerator->node),
154-
$identifiedGenerator->node->getStartLine(),
155-
);
141+
$stackTrace[] = $string;
156142
}
157143

158144
throw new TrampolineException(sprintf(

src/Analyser/Generator/IdentifiedGeneratorInStack.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
namespace PHPStan\Analyser\Generator;
44

55
use Generator;
6+
use Override;
67
use PhpParser\Node;
8+
use function get_class;
9+
use function is_array;
10+
use function sprintf;
711

812
/**
913
* @phpstan-import-type GeneratorTValueType from GeneratorNodeScopeResolver
@@ -33,4 +37,28 @@ public function __construct(
3337
{
3438
}
3539

40+
#[Override]
41+
public function __toString(): string
42+
{
43+
if ($this->file === null || $this->line === null) {
44+
return '';
45+
}
46+
47+
if (is_array($this->node)) {
48+
return sprintf(
49+
"Stmts\n -> %s on line %d",
50+
$this->file,
51+
$this->line,
52+
);
53+
}
54+
55+
return sprintf(
56+
"%s:%d\n -> %s on line %d",
57+
$this->file,
58+
$this->line,
59+
get_class($this->node),
60+
$this->node->getStartLine(),
61+
);
62+
}
63+
3664
}

0 commit comments

Comments
 (0)