diff --git a/library/Icingadb/Util/PluginOutput.php b/library/Icingadb/Util/PluginOutput.php index 71d08b131..03055a9ef 100644 --- a/library/Icingadb/Util/PluginOutput.php +++ b/library/Icingadb/Util/PluginOutput.php @@ -64,6 +64,9 @@ class PluginOutput extends HtmlString /** @var bool Whether the output contains HTML */ protected $isHtml; + /** @var int The maximum amount of characters to process */ + protected $characterLimit = 1000; + /** @var bool Whether output will be enriched */ protected $enrichOutput = true; @@ -93,6 +96,20 @@ public function isHtml(): bool return $this->isHtml; } + /** + * Set the maximum amount of characters to process + * + * @param int $limit + * + * @return $this + */ + public function setCharacterLimit(int $limit): self + { + $this->characterLimit = $limit; + + return $this; + } + /** * Set whether the output should be enriched * @@ -185,6 +202,10 @@ public function render() $output = $this->processHtml($output); } + if ($this->characterLimit) { + $output = substr($output, 0, $this->characterLimit); + } + $this->renderedOutput = $output; return $output; diff --git a/phpstan-baseline-standard.neon b/phpstan-baseline-standard.neon index 960709e7e..d9d2d72e0 100644 --- a/phpstan-baseline-standard.neon +++ b/phpstan-baseline-standard.neon @@ -5067,7 +5067,7 @@ parameters: - message: "#^Parameter \\#1 \\$string of function substr expects string, string\\|null given\\.$#" - count: 2 + count: 3 path: library/Icingadb/Util/PluginOutput.php -