Skip to content

Commit a9e05a3

Browse files
authored
Merge pull request #56 from psalm/update-psalm
Allow Psalm 6 and fix newly detected errors
2 parents 8b8f4dd + c7c1293 commit a9e05a3

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
},
2626
"require-dev": {
2727
"squizlabs/php_codesniffer": "^3.4",
28-
"vimeo/psalm": "^4.17.0 || dev-master || ^5.0.0 || dev-master",
28+
"vimeo/psalm": "^4.17.0 || dev-master || ^5.0.0 || ^6.0.0 || dev-master",
2929
"phpunit/phpunit": "^9.5.20",
3030
"codeception/codeception": "^4.1.31 || ^5.0.0-rc3"
3131
},

src/Module.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
use function is_numeric;
2929
use function is_string;
3030

31+
/** @api */
3132
class Module extends BaseModule
3233
{
3334
/** @var array<string,string> */
@@ -144,6 +145,10 @@ public function runPsalmOn(string $filename, array $options = []): void
144145
public function runPsalmIn(string $dir, array $options = []): void
145146
{
146147
$pwd = getcwd();
148+
if (false === $pwd) {
149+
throw new TestRuntimeException('Failed to get current working directory');
150+
}
151+
147152
$this->fs()->amInPath($dir);
148153

149154
$config = $this->psalmConfig ?: self::DEFAULT_PSALM_CONFIG;
@@ -197,7 +202,11 @@ public function seeThisError(string $type, string $message): void
197202
private function matches(string $expected, string $actual): bool
198203
{
199204
$regexpDelimiter = '/';
200-
if ($expected[0] === $regexpDelimiter && $expected[strlen($expected) - 1] === $regexpDelimiter) {
205+
if (
206+
$expected !== ''
207+
&& $expected[0] === $regexpDelimiter
208+
&& $expected[strlen($expected) - 1] === $regexpDelimiter
209+
) {
201210
$regexp = $expected;
202211
} else {
203212
$regexp = $this->convertToRegexp($expected);
@@ -319,6 +328,10 @@ public function runPsalmWithTaintAnalysis(): void
319328
public function runPsalmOnASingleFile(string $file): void
320329
{
321330
$pwd = getcwd();
331+
if (false === $pwd) {
332+
throw new TestRuntimeException('Failed to get current working directory');
333+
}
334+
322335
$this->fs()->amInPath($this->getDefaultDirectory());
323336

324337
$config = $this->psalmConfig ?: self::DEFAULT_PSALM_CONFIG;
@@ -473,6 +486,7 @@ public function haveADependencySatisfied(string $package, string $versionConstra
473486
throw new SkippedTestError("This scenario requires $package to match $versionConstraint");
474487
}
475488

489+
/** @return non-empty-string */
476490
private function convertToRegexp(string $in): string
477491
{
478492
return '@' . str_replace('%', '.*', preg_quote($in, '@')) . '@';
@@ -552,7 +566,7 @@ private function parseErrors(): void
552566
return;
553567
}
554568

555-
if (empty($this->output)) {
569+
if ($this->output === null || $this->output === '') {
556570
$this->errors = [];
557571
return;
558572
}

tests/acceptance/PsalmModule.feature

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ Feature: Psalm module
7878
"""
7979
When I run Psalm with dead code detection
8080
Then I see these errors
81-
| Type | Message |
82-
| UnusedParam | Param $p is never referenced in this method |
83-
| UnusedClass | Class CD is never used |
81+
| Type | Message |
82+
| UnusedParam | /Param \$?p is never referenced in this method/ |
83+
| UnusedClass | Class CD is never used |
8484
And I see no other errors
8585

8686
Scenario: Running Psalm with custom config
@@ -174,6 +174,7 @@ Feature: Psalm module
174174
Scenario: Using regexps to match error messages
175175
Given I have the following code
176176
"""
177+
/** @api */
177178
class CCC extends PPP {}
178179
"""
179180
When I run Psalm
@@ -185,6 +186,7 @@ Feature: Psalm module
185186
Scenario: Escaping pipes in regexps
186187
Given I have the following code
187188
"""
189+
/** @api */
188190
class CC extends PPP {}
189191
"""
190192
When I run Psalm
@@ -196,6 +198,7 @@ Feature: Psalm module
196198
Scenario: Using backslashes in regexps
197199
Given I have the following code
198200
"""
201+
/** @api */
199202
class C extends PPP {}
200203
"""
201204
When I run Psalm

0 commit comments

Comments
 (0)