Skip to content

Commit 277f7a3

Browse files
committed
Added psalm to static analyze tools
1 parent e8373af commit 277f7a3

File tree

4 files changed

+33
-13
lines changed

4 files changed

+33
-13
lines changed

.phive/phars.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
<phar name="php-cs-fixer" version="^2.16.4" installed="2.16.4" location="./tools/php-cs-fixer" copy="true"/>
44
<phar name="phpstan" version="^0.12.32" installed="0.12.32" location="./tools/phpstan" copy="true"/>
55
<phar name="roave/backwardcompatibilitycheck" version="^5.0.0" installed="5.0.0" location="./tools/roave-backward-compatibility-check" copy="true"/>
6+
<phar name="psalm" version="^3.12.2" installed="3.12.2" location="./tools/psalm" copy="true"/>
67
</phive>

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"phpunit"
5353
],
5454
"static:analyze": [
55+
"tools/psalm",
5556
"tools/phpstan analyze -c phpstan.neon",
5657
"tools/php-cs-fixer fix --dry-run"
5758
]

psalm.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0"?>
2+
<psalm
3+
errorLevel="5"
4+
resolveFromConfigFile="true"
5+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6+
xmlns="https://getpsalm.org/schema/config"
7+
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
8+
cacheDirectory="var/psalm/cache"
9+
>
10+
<projectFiles>
11+
<directory name="src" />
12+
<ignoreFiles>
13+
<directory name="vendor" />
14+
</ignoreFiles>
15+
</projectFiles>
16+
</psalm>

src/Parser.php

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,7 @@ private function getPattern() : AST\Pattern
7676
break;
7777

7878
default:
79-
$this->unexpectedSyntaxError($this->lexer->lookahead, '@type@ pattern');
80-
81-
break;
79+
throw PatternException::syntaxError($this->unexpectedSyntaxError($this->lexer->lookahead, '@type@ pattern'));
8280
}
8381

8482
$this->lexer->moveNext();
@@ -119,7 +117,7 @@ private function getNextExpanderNode() : ?AST\Expander
119117
}
120118

121119
if (!$this->isNextCloseParenthesis()) {
122-
$this->unexpectedSyntaxError($this->lexer->lookahead, ')');
120+
throw PatternException::syntaxError($this->unexpectedSyntaxError($this->lexer->lookahead, ')'));
123121
}
124122

125123
return $expander;
@@ -128,9 +126,15 @@ private function getNextExpanderNode() : ?AST\Expander
128126
private function getExpanderName() : string
129127
{
130128
if ($this->lexer->lookahead['type'] !== Lexer::T_EXPANDER_NAME) {
131-
$this->unexpectedSyntaxError($this->lexer->lookahead, '.expanderName(args) definition');
129+
throw PatternException::syntaxError($this->unexpectedSyntaxError($this->lexer->lookahead, '.expanderName(args) definition'));
132130
}
131+
133132
$expander = $this->lexer->lookahead['value'];
133+
134+
if ($expander === null) {
135+
throw PatternException::syntaxError($this->unexpectedSyntaxError($this->lexer->lookahead, '.expanderName(args) definition'));
136+
}
137+
134138
$this->lexer->moveNext();
135139

136140
return $expander;
@@ -152,7 +156,7 @@ private function addArgumentValues(AST\Expander $expander) : void
152156
$this->lexer->moveNext();
153157

154158
if ($this->lexer->isNextToken(Lexer::T_CLOSE_PARENTHESIS)) {
155-
$this->unexpectedSyntaxError($this->lexer->lookahead, 'string, number, boolean or null argument');
159+
throw PatternException::syntaxError($this->unexpectedSyntaxError($this->lexer->lookahead, 'string, number, boolean or null argument'));
156160
}
157161
}
158162
}
@@ -182,7 +186,7 @@ private function getNextArgumentValue()
182186
}
183187

184188
if (!$this->lexer->isNextTokenAny($validArgumentTypes)) {
185-
$this->unexpectedSyntaxError($this->lexer->lookahead, 'string, number, boolean or null argument');
189+
throw PatternException::syntaxError($this->unexpectedSyntaxError($this->lexer->lookahead, 'string, number, boolean or null argument'));
186190
}
187191

188192
$tokenType = $this->lexer->lookahead['type'];
@@ -206,7 +210,7 @@ private function getArrayArgument() : array
206210
}
207211

208212
if (!$this->lexer->isNextToken(Lexer::T_CLOSE_CURLY_BRACE)) {
209-
$this->unexpectedSyntaxError($this->lexer->lookahead, '}');
213+
throw PatternException::syntaxError($this->unexpectedSyntaxError($this->lexer->lookahead, '}'));
210214
}
211215

212216
$this->lexer->moveNext();
@@ -227,7 +231,7 @@ private function getNextArrayElement(array &$array)
227231
}
228232

229233
if (!$this->lexer->isNextToken(Lexer::T_COLON)) {
230-
$this->unexpectedSyntaxError($this->lexer->lookahead, ':');
234+
throw PatternException::syntaxError($this->unexpectedSyntaxError($this->lexer->lookahead, ':'));
231235
}
232236

233237
$this->lexer->moveNext();
@@ -258,17 +262,15 @@ private function isNextCloseParenthesis() : bool
258262
/**
259263
* @param array $unexpectedToken
260264
* @param string $expected
261-
*
262-
* @throws PatternException
263265
*/
264-
private function unexpectedSyntaxError(array $unexpectedToken, string $expected = null) : void
266+
private function unexpectedSyntaxError(array $unexpectedToken, string $expected = null) : string
265267
{
266268
$tokenPos = (isset($unexpectedToken['position'])) ? $unexpectedToken['position'] : '-1';
267269
$message = \sprintf('line 0, col %d: Error: ', $tokenPos);
268270
$message .= (isset($expected)) ? \sprintf('Expected "%s", got ', $expected) : 'Unexpected';
269271
$message .= \sprintf('"%s"', $unexpectedToken['value']);
270272

271-
throw PatternException::syntaxError($message);
273+
return $message;
272274
}
273275

274276
/**

0 commit comments

Comments
 (0)