Skip to content

Commit f9aa2eb

Browse files
committed
Allow Psalm 6 and fix newly detected errors
1 parent 8b8f4dd commit f9aa2eb

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
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
}

0 commit comments

Comments
 (0)