diff --git a/CHANGELOG.md b/CHANGELOG.md index f549fec..936d2c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## 4.1.1 under development -- no changes in this release. +- Enh #150: Cleanup templates, remove legacy code (@vjik) ## 4.1.0 April 18, 2025 diff --git a/composer.json b/composer.json index 861c116..3c14886 100644 --- a/composer.json +++ b/composer.json @@ -49,13 +49,13 @@ "require-dev": { "bamarni/composer-bin-plugin": "^1.8.2", "httpsoft/http-message": "^1.1.6", - "phpunit/phpunit": "^10.5.45", + "phpunit/phpunit": "^10.5.51", "psr/event-dispatcher": "^1.0", - "rector/rector": "^2.0.11", + "rector/rector": "^2.1.3", "roave/infection-static-analysis-plugin": "^1.35", "spatie/phpunit-watcher": "^1.24", - "vimeo/psalm": "^5.26.1 || ^6.9.1", - "yiisoft/di": "^1.3", + "vimeo/psalm": "^5.26.1 || ^6.13.1", + "yiisoft/di": "^1.4", "yiisoft/test-support": "^3.0.2" }, "autoload": { diff --git a/psalm.xml b/psalm.xml index 39a3bda..ee1d4e0 100644 --- a/psalm.xml +++ b/psalm.xml @@ -11,6 +11,7 @@ > + diff --git a/src/Exception/ErrorException.php b/src/Exception/ErrorException.php index 0346c26..7856366 100644 --- a/src/Exception/ErrorException.php +++ b/src/Exception/ErrorException.php @@ -14,7 +14,16 @@ /** * `ErrorException` represents a PHP error. - * @psalm-type DebugBacktraceType = list,class?:class-string,file?:string,function:string,line?:int,object?:object,type?:string}> + * + * @psalm-type DebugBacktraceType = list, + * class?: class-string, + * file?: string, + * function?: string, + * line?: int, + * object?: object, + * type?: string + * }> * * @final */ @@ -121,7 +130,6 @@ private function addXDebugTraceToFatalIfAvailable(): void } $ref = new ReflectionProperty(Exception::class, 'trace'); - $ref->setAccessible(true); $ref->setValue($this, $trace); } } diff --git a/src/Renderer/HtmlRenderer.php b/src/Renderer/HtmlRenderer.php index c85acb0..5f6d1ce 100644 --- a/src/Renderer/HtmlRenderer.php +++ b/src/Renderer/HtmlRenderer.php @@ -86,7 +86,7 @@ final class HtmlRenderer implements ThrowableRendererInterface private readonly int $maxTraceLines; /** - * @var string|null The trace header line with placeholders to be be substituted. Defaults to null. + * @var string|null The trace header line with placeholders to be substituted. Defaults to null. * * The placeholders are {file}, {line} and {icon}. A typical use case is the creation of IDE-specific links, * since when you click on a trace header link, it opens directly in the IDE. You can also insert custom content. @@ -97,7 +97,7 @@ final class HtmlRenderer implements ThrowableRendererInterface * {icon} * ``` */ - private readonly ?string $traceHeaderLine; + public readonly ?string $traceHeaderLine; /** * @var string[]|null The list of vendor paths is determined automatically. @@ -632,8 +632,6 @@ private function groupVendorCallStackItems(array $items): array $groupedItems[$groupIndex][$index] = $item; } - /** @psalm-var array> $groupedItems It's needed for Psalm <=4.30 only. */ - return $groupedItems; } diff --git a/templates/_call-stack-item.php b/templates/_call-stack-item.php index 41d3157..9940d35 100644 --- a/templates/_call-stack-item.php +++ b/templates/_call-stack-item.php @@ -14,7 +14,6 @@ * @var array $args * @var bool $isVendorFile * @var ReflectionMethod[] $reflectionParameters - * @var HtmlRenderer $this */ $icon = << HTML; + +/** + * @var HtmlRenderer $this + */ ?>
  • + data-line="">
    htmlEncode($file)}" ?> traceHeaderLine !== null): ?> - traceHeaderLine, ['{file}' => $file, '{line}' => $line + 1, '{icon}' => $icon]) ?> + traceHeaderLine, ['{file}' => $file, '{line}' => (int) $line + 1, '{icon}' => $icon]) ?> @@ -75,7 +78,7 @@ $htmlEncode( is_int($key) && isset($reflectionParameters[$key]) ? $reflectionParameters[$key]->getName() - : $key + : (string) $key ) ?> diff --git a/templates/_call-stack-items.php b/templates/_call-stack-items.php index be16a45..caeaffa 100644 --- a/templates/_call-stack-items.php +++ b/templates/_call-stack-items.php @@ -1,22 +1,34 @@ */ -/* @var $vendorItemGroups array> */ -/* @var $this \Yiisoft\ErrorHandler\Renderer\HtmlRenderer */ -$insertItem = static function (array &$items, array $item, int $offset = 0): void { - $itemIndex = array_key_first($item); - foreach (array_keys($items) as $index) { - $offset++; - if ($index === ($itemIndex - 1)) { - break; + +use Yiisoft\ErrorHandler\Renderer\HtmlRenderer; + +/** + * @psalm-var array $applicationItems + * @psalm-var array> $vendorItemGroups + * @var HtmlRenderer $this + */ + +$insertItem = + /** + * @psalm-param array $items + * @psalm-param non-empty-array $item + */ + static function (array &$items, array $item, int $offset = 0): void { + $itemIndex = array_key_first($item); + foreach (array_keys($items) as $index) { + $offset++; + if ($index === ($itemIndex - 1)) { + break; + } } - } - $items = array_slice($items, 0, $offset, true) + $item + array_slice($items, $offset, null, true); -}; + $items = array_slice($items, 0, $offset, true) + $item + array_slice($items, $offset, null, true); + }; foreach ($vendorItemGroups as $key => $vendorItemGroup) { $count = count($vendorItemGroup); if ($count === 0) { continue; } + /** @psalm-var non-empty-array $vendorItemGroup */ if ($count === 1) { $insertItem($applicationItems, $vendorItemGroup); continue; diff --git a/templates/_previous-exception.php b/templates/_previous-exception.php index 7e07ceb..7571ba4 100644 --- a/templates/_previous-exception.php +++ b/templates/_previous-exception.php @@ -1,6 +1,11 @@