Skip to content

Increase psalm error level to 1#84

Merged
samdark merged 5 commits intoyiisoft:masterfrom
dood-:psalm-1
Jul 14, 2022
Merged

Increase psalm error level to 1#84
samdark merged 5 commits intoyiisoft:masterfrom
dood-:psalm-1

Conversation

@dood-
Copy link
Copy Markdown
Contributor

@dood- dood- commented Jul 13, 2022

Q A
Is bugfix?
New feature?
Breaks BC?
Fixed issues #78

Comment thread src/Message.php
Comment thread src/Message/Formatter.php Outdated
{
$timestamp = (string) $message->context('time', microtime(true));
/** @var float $timestamp */
$timestamp = $message->context('time', microtime(true));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$timestamp = $message->context('time', microtime(true));
$timestamp = (string) $message->context('time', microtime(true));

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Psalm shows error without the type declaration

PossiblyInvalidCast - src/Message/Formatter.php:146:31 - array{category?: string, memory?: int, time?: float, trace?: list<array{class?: string, file: string, function?: string, line: int, type?: string}>} cannot be cast to string (see https://psalm.dev/190)
        $timestamp = (string) $message->context('time', microtime(true));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Psalm can not determine type of result, but we known that for time always returns float. I think we can suppress this error.

Comment thread src/Message.php Outdated
Comment on lines +23 to +24
* args?:array,
* object?:object,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keys "args" and "object" removed in Logger::collectTrace().

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Psalm shows errors without these keys

ERROR: InvalidArrayOffset - src/Logger.php:316:31 - Cannot access value on variable $trace using offset value of 'object', expecting 'file', 'line', 'function', 'class' or 'type' (see https://psalm.dev/115)
                        unset($trace['object'], $trace['args']);

Can be solved by adding array to the type

* @psalm-type Backtrace = list<array{
 *     file:string,
 *     line:int,
 *     function?:string,
 *     class?:string,
 *     type?:string,
 * }&array>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To method Logger::collectTrace pass parameter:

list<array{
	file:string,
	line:int,
	function?:string,
	class?:string,
	type?:string,
	args?:array,
	object?:object,
}>

..., but result of method is:

list<array{
	file:string,
	line:int,
	function?:string,
	class?:string,
	type?:string,
}>

Comment thread src/Message/Formatter.php
Comment thread src/Message/Formatter.php Outdated
@samdark samdark merged commit 230f89c into yiisoft:master Jul 14, 2022
@samdark
Copy link
Copy Markdown
Member

samdark commented Jul 14, 2022

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants