Skip to content

Commit

Permalink
Fix native printer literals
Browse files Browse the repository at this point in the history
  • Loading branch information
SerafimArts committed Jan 11, 2025
1 parent 9e3cf12 commit aab010d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
1 change: 0 additions & 1 deletion resources/aliases/phpstan.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
'non-empty-list' => 'array',
// object
'callable-object' => 'object',
'$this' => 'object',
// callable
'pure-callable' => 'callable',
'pure-closure' => '\Closure',
Expand Down
1 change: 0 additions & 1 deletion resources/aliases/psalm.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
'private-properties-of' => 'array',
'properties-of' => 'array',
// object
'$this' => 'object',
'callable-object' => 'object',
'stringable-object' => '\Stringable',
// callable
Expand Down
23 changes: 14 additions & 9 deletions src/NativeTypePrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@

namespace TypeLang\Printer;

use TypeLang\Parser\Node\Literal\BoolLiteralNode;
use TypeLang\Parser\Node\Literal\FloatLiteralNode;
use TypeLang\Parser\Node\Literal\IntLiteralNode;
use TypeLang\Parser\Node\Literal\LiteralNode;
use TypeLang\Parser\Node\Literal\NullLiteralNode;
use TypeLang\Parser\Node\Literal\StringLiteralNode;
use TypeLang\Parser\Node\Literal\VariableLiteralNode;
use TypeLang\Parser\Node\Stmt\CallableTypeNode;
use TypeLang\Parser\Node\Stmt\ClassConstMaskNode;
Expand Down Expand Up @@ -226,15 +231,15 @@ protected function printNamedTypeNode(NamedTypeNode $node): string
#[\Override]
protected function printLiteralNode(LiteralNode $node): string
{
if ($node instanceof VariableLiteralNode) {
if ($node->getValue() === 'this') {
return 'self';
}

return 'mixed';
}

return \get_debug_type($node->getRawValue());
return match (true) {

Check failure on line 234 in src/NativeTypePrinter.php

View workflow job for this annotation

GitHub Actions / Linter (8.4, ubuntu-latest)

Method TypeLang\Printer\NativeTypePrinter::printLiteralNode() should return non-empty-string but returns string.
$node instanceof BoolLiteralNode => 'bool',
$node instanceof FloatLiteralNode => 'float',
$node instanceof IntLiteralNode => 'int',
$node instanceof NullLiteralNode => 'null',
$node instanceof StringLiteralNode => 'string',
$node instanceof VariableLiteralNode => $node->getValue() === 'this' ? 'self' : 'mixed',
default => \get_debug_type($node->getValue()),
};
}

#[\Override]
Expand Down

0 comments on commit aab010d

Please sign in to comment.