Skip to content
Merged
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
8 changes: 7 additions & 1 deletion src/Type/Constant/ConstantStringType.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,14 @@ function (): string {
return var_export($this->value, true);
}

try {
$truncatedValue = \Nette\Utils\Strings::truncate($this->value, self::DESCRIBE_LIMIT);
} catch (\Nette\Utils\RegexpException $e) {
$truncatedValue = substr($this->value, 0, self::DESCRIBE_LIMIT) . "\u{2026}";
}

return var_export(
\Nette\Utils\Strings::truncate($this->value, self::DESCRIBE_LIMIT),
$truncatedValue,
true
);
},
Expand Down
10 changes: 10 additions & 0 deletions tests/PHPStan/Type/Constant/ConstantStringTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,14 @@ public function testGeneralize(): void
$this->assertSame('class-string', (new ConstantStringType('NonexistentClass', true))->generalize()->describe(VerbosityLevel::precise()));
}

public function testTextInvalidEncoding(): void
{
$this->assertSame("'\xc3Lorem ipsum dolor s\u{2026}'", (new ConstantStringType("\xc3Lorem ipsum dolor sit"))->describe(VerbosityLevel::value()));
}

public function testShortTextInvalidEncoding(): void
{
$this->assertSame("'\xc3Lorem ipsum dolor'", (new ConstantStringType("\xc3Lorem ipsum dolor"))->describe(VerbosityLevel::value()));
}

}