Skip to content

Commit 879e7d1

Browse files
dependabot[bot]vjikStyleCIBot
authored
Update psalm verison + Psalm level 1 (#69)
* Update vimeo/psalm requirement from ^4.18 to ^5.3 Updates the requirements on [vimeo/psalm](https://github.com/vimeo/psalm) to permit the latest version. - [Release notes](https://github.com/vimeo/psalm/releases) - [Commits](vimeo/psalm@4.18...5.3.0) --- updated-dependencies: - dependency-name: vimeo/psalm dependency-type: direct:development ... Signed-off-by: dependabot[bot] <[email protected]> * Update composer.json * fix tests * fix psalm bug * level 1 * Apply fixes from StyleCI * fix --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Sergei Predvoditelev <[email protected]> Co-authored-by: StyleCI Bot <[email protected]>
1 parent e3cd5a3 commit 879e7d1

File tree

7 files changed

+37
-7
lines changed

7 files changed

+37
-7
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"rector/rector": "^0.15.10",
4545
"roave/infection-static-analysis-plugin": "^1.16",
4646
"spatie/phpunit-watcher": "^1.23",
47-
"vimeo/psalm": "^4.18",
47+
"vimeo/psalm": "^4.30|^5.6",
4848
"yiisoft/test-support": "^1.3"
4949
},
5050
"autoload": {

psalm.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?xml version="1.0"?>
22
<psalm
3-
errorLevel="2"
3+
errorLevel="1"
4+
findUnusedBaselineEntry="true"
5+
findUnusedCode="false"
46
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
57
xmlns="https://getpsalm.org/schema/config"
68
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"

src/Exception/ErrorException.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,12 @@ public function getSolution(): ?string
8383
private function addXDebugTraceToFatalIfAvailable(): void
8484
{
8585
if ($this->isXdebugStackAvailable()) {
86-
// XDebug trace can't be modified and used directly with PHP 7
87-
// @see https://github.com/yiisoft/yii2/pull/11723
86+
/**
87+
* XDebug trace can't be modified and used directly with PHP 7
88+
*
89+
* @see https://github.com/yiisoft/yii2/pull/11723
90+
* @psalm-var array<int,array>
91+
*/
8892
$xDebugTrace = array_slice(array_reverse(xdebug_get_function_stack()), 1, -1);
8993
$trace = [];
9094

@@ -102,6 +106,7 @@ private function addXDebugTraceToFatalIfAvailable(): void
102106

103107
// XDebug has a different key name
104108
if (isset($frame['params']) && !isset($frame['args'])) {
109+
/** @var mixed */
105110
$frame['args'] = $frame['params'];
106111
}
107112
$trace[] = $frame;

src/Middleware/ErrorCatcher.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
*/
3838
final class ErrorCatcher implements MiddlewareInterface
3939
{
40+
/**
41+
* @psalm-var array<string,class-string<ThrowableRendererInterface>>
42+
*/
4043
private array $renderers = [
4144
'application/json' => JsonRenderer::class,
4245
'application/xml' => XmlRenderer::class,
@@ -146,6 +149,7 @@ private function generateErrorResponse(Throwable $t, ServerRequestInterface $req
146149
private function getRenderer(string $contentType): ?ThrowableRendererInterface
147150
{
148151
if (isset($this->renderers[$contentType])) {
152+
/** @var ThrowableRendererInterface */
149153
return $this->container->get($this->renderers[$contentType]);
150154
}
151155

src/Middleware/ExceptionResponder.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
7373
}
7474

7575
if (is_callable($responseHandler)) {
76+
/** @var ResponseInterface */
7677
return $this->injector->invoke($responseHandler, ['exception' => $t]);
7778
}
7879
}

src/Renderer/HtmlRenderer.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,14 @@ final class HtmlRenderer implements ThrowableRendererInterface
108108
* - maxSourceLines: int, maximum number of source code lines to be displayed. Defaults to 19.
109109
* - maxTraceLines: int, maximum number of trace source code lines to be displayed. Defaults to 13.
110110
* - traceHeaderLine: string, trace header line with placeholders to be be substituted. Defaults to null.
111+
*
112+
* @psalm-param array{
113+
* template?: string,
114+
* verboseTemplate?: string,
115+
* maxSourceLines?: int,
116+
* maxTraceLines?: int,
117+
* traceHeaderLine?: string,
118+
* } $settings
111119
*/
112120
public function __construct(array $settings = [])
113121
{
@@ -264,6 +272,9 @@ public function argumentsToString(array $args): string
264272
$count = 0;
265273
$isAssoc = $args !== array_values($args);
266274

275+
/**
276+
* @var mixed $value
277+
*/
267278
foreach ($args as $key => $value) {
268279
$count++;
269280

@@ -306,6 +317,8 @@ public function argumentsToString(array $args): string
306317
}
307318
}
308319

320+
/** @var string[] $args */
321+
309322
ksort($args);
310323
return implode(', ', $args);
311324
}
@@ -423,6 +436,7 @@ private function renderTemplate(string $path, array $parameters): string
423436
}
424437

425438
$renderer = function (): void {
439+
/** @psalm-suppress MixedArgument */
426440
extract(func_get_arg(1), EXTR_OVERWRITE);
427441
require func_get_arg(0);
428442
};
@@ -524,6 +538,8 @@ private function groupVendorCallStackItems(array $items): array
524538
$groupedItems[$groupIndex][$index] = $item;
525539
}
526540

541+
/** @psalm-var array<int, array<int, string>> $groupedItems It's need for Psalm <=4.30 only. */
542+
527543
return $groupedItems;
528544
}
529545

@@ -571,6 +587,7 @@ private function getVendorPaths(): array
571587
$rootPath = dirname(__DIR__, 4);
572588

573589
// If the error handler is installed as a vendor package.
590+
/** @psalm-suppress InvalidLiteralArgument It is Psalm bug, {@see https://github.com/vimeo/psalm/issues/9196} */
574591
if (strlen($rootPath) > 6 && str_contains($rootPath, 'vendor')) {
575592
$this->vendorPaths = [$rootPath];
576593
return $this->vendorPaths;
@@ -579,6 +596,7 @@ private function getVendorPaths(): array
579596
// If the error handler is installed for development in `yiisoft/yii-dev-tool`.
580597
if (is_file("{$rootPath}/yii-dev") || is_file("{$rootPath}/yii-dev.bat")) {
581598
$vendorPaths = glob("{$rootPath}/dev/*/vendor");
599+
/** @var string[] */
582600
$this->vendorPaths = empty($vendorPaths) ? [] : str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $vendorPaths);
583601
return $this->vendorPaths;
584602
}

tests/Middleware/ErrorCatcherTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function testAddedRenderer(): void
8484
public function testThrownExceptionWithRendererIsNotImplementThrowableRendererInterface()
8585
{
8686
$this->expectException(InvalidArgumentException::class);
87-
$this->expectErrorMessage(
87+
$this->expectExceptionMessage(
8888
'Class "' . self::class . '" does not implement "' . ThrowableRendererInterface::class . '".',
8989
);
9090
$this
@@ -95,7 +95,7 @@ public function testThrownExceptionWithRendererIsNotImplementThrowableRendererIn
9595
public function testThrownExceptionWithInvalidContentType()
9696
{
9797
$this->expectException(InvalidArgumentException::class);
98-
$this->expectErrorMessage('Invalid content type.');
98+
$this->expectExceptionMessage('Invalid content type.');
9999
$this
100100
->createErrorCatcher()
101101
->withRenderer('test invalid content type', PlainTextRenderer::class);
@@ -197,7 +197,7 @@ public function testForceContentType(): void
197197
public function testForceContentTypeSetInvalidType(): void
198198
{
199199
$this->expectException(InvalidArgumentException::class);
200-
$this->expectErrorMessage('The renderer for image/gif is not set.');
200+
$this->expectExceptionMessage('The renderer for image/gif is not set.');
201201
$this
202202
->createErrorCatcher()
203203
->forceContentType('image/gif');

0 commit comments

Comments
 (0)