Skip to content

Commit ceba775

Browse files
committed
fix phpstan issues
1 parent 8198555 commit ceba775

1 file changed

Lines changed: 24 additions & 27 deletions

File tree

src/JsNodeVisitor.php

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@
33

44
namespace Gettext\Scanner;
55

6+
use InvalidArgumentException;
67
use Peast\Syntax\Node\CallExpression;
78
use Peast\Syntax\Node\Comment;
9+
use Peast\Syntax\Node\Identifier;
10+
use Peast\Syntax\Node\Literal;
11+
use Peast\Syntax\Node\MemberExpression;
812
use Peast\Syntax\Node\Node;
13+
use Peast\Syntax\Node\TemplateLiteral;
914

1015
class JsNodeVisitor
1116
{
@@ -21,7 +26,7 @@ public function __construct(string $filename, array $validFunctions = null)
2126

2227
public function __invoke(Node $node): void
2328
{
24-
if ($node->getType() === 'CallExpression') {
29+
if ($node instanceof CallExpression) {
2530
$function = $this->createFunction($node);
2631

2732
if ($function) {
@@ -55,24 +60,20 @@ protected function createFunction(CallExpression $node): ?ParsedFunction
5560
static::addComments($function, $node->getCallee());
5661

5762
foreach ($node->getArguments() as $argument) {
58-
switch ($argument->getType()) {
59-
case 'Literal':
60-
$function->addArgument($argument->getValue());
61-
static::addComments($function, $argument);
62-
break;
63-
case 'TemplateLiteral':
64-
if ($argument->getExpressions()) {
65-
$function->addArgument();
66-
break;
67-
}
68-
63+
if ($argument instanceof Literal) {
64+
$function->addArgument($argument->getValue());
65+
static::addComments($function, $argument);
66+
} elseif ($argument instanceof TemplateLiteral) {
67+
if ($argument->getExpressions()) {
68+
$function->addArgument();
69+
} else {
6970
$quasis = $argument->getQuasis();
7071
$quasis = array_shift($quasis);
7172
$function->addArgument($quasis->getValue());
7273
static::addComments($function, $argument);
73-
break;
74-
default:
75-
$function->addArgument();
74+
}
75+
} else {
76+
$function->addArgument();
7677
}
7778
}
7879

@@ -83,19 +84,15 @@ protected static function getFunctionName(CallExpression $node): ?string
8384
{
8485
$callee = $node->getCallee();
8586

86-
switch ($callee->getType()) {
87-
case 'Identifier':
88-
return $callee->getName();
89-
case 'MemberExpression':
90-
$property = $callee->getProperty();
91-
92-
if ($property->getType() === 'Identifier') {
93-
return $property->getName();
94-
}
95-
return null;
96-
default:
97-
return null;
87+
if ($callee instanceof Identifier) {
88+
return $callee->getName();
89+
} elseif ($callee instanceof MemberExpression) {
90+
$property = $callee->getProperty();
91+
if ($property instanceof Identifier) {
92+
return $property->getName();
93+
}
9894
}
95+
return null;
9996
}
10097

10198
protected static function addComments(ParsedFunction $function, Node $node): void

0 commit comments

Comments
 (0)