Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
"require-dev": {
"squizlabs/php_codesniffer": "^3.4",
"vimeo/psalm": "^4.17.0 || dev-master || ^5.0.0 || dev-master",
"vimeo/psalm": "^4.17.0 || dev-master || ^5.0.0 || ^6.0.0 || dev-master",
"phpunit/phpunit": "^9.5.20",
"codeception/codeception": "^4.1.31 || ^5.0.0-rc3"
},
Expand Down
18 changes: 16 additions & 2 deletions src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use function is_numeric;
use function is_string;

/** @api */
class Module extends BaseModule
{
/** @var array<string,string> */
Expand Down Expand Up @@ -144,6 +145,10 @@ public function runPsalmOn(string $filename, array $options = []): void
public function runPsalmIn(string $dir, array $options = []): void
{
$pwd = getcwd();
if (false === $pwd) {
throw new TestRuntimeException('Failed to get current working directory');
}

$this->fs()->amInPath($dir);

$config = $this->psalmConfig ?: self::DEFAULT_PSALM_CONFIG;
Expand Down Expand Up @@ -197,7 +202,11 @@ public function seeThisError(string $type, string $message): void
private function matches(string $expected, string $actual): bool
{
$regexpDelimiter = '/';
if ($expected[0] === $regexpDelimiter && $expected[strlen($expected) - 1] === $regexpDelimiter) {
if (
$expected !== ''
&& $expected[0] === $regexpDelimiter
&& $expected[strlen($expected) - 1] === $regexpDelimiter
) {
$regexp = $expected;
} else {
$regexp = $this->convertToRegexp($expected);
Expand Down Expand Up @@ -319,6 +328,10 @@ public function runPsalmWithTaintAnalysis(): void
public function runPsalmOnASingleFile(string $file): void
{
$pwd = getcwd();
if (false === $pwd) {
throw new TestRuntimeException('Failed to get current working directory');
}

$this->fs()->amInPath($this->getDefaultDirectory());

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

/** @return non-empty-string */
private function convertToRegexp(string $in): string
{
return '@' . str_replace('%', '.*', preg_quote($in, '@')) . '@';
Expand Down Expand Up @@ -552,7 +566,7 @@ private function parseErrors(): void
return;
}

if (empty($this->output)) {
if ($this->output === null || $this->output === '') {
$this->errors = [];
return;
}
Expand Down
9 changes: 6 additions & 3 deletions tests/acceptance/PsalmModule.feature
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ Feature: Psalm module
"""
When I run Psalm with dead code detection
Then I see these errors
| Type | Message |
| UnusedParam | Param $p is never referenced in this method |
| UnusedClass | Class CD is never used |
| Type | Message |
| UnusedParam | /Param \$?p is never referenced in this method/ |
| UnusedClass | Class CD is never used |
And I see no other errors

Scenario: Running Psalm with custom config
Expand Down Expand Up @@ -174,6 +174,7 @@ Feature: Psalm module
Scenario: Using regexps to match error messages
Given I have the following code
"""
/** @api */
class CCC extends PPP {}
"""
When I run Psalm
Expand All @@ -185,6 +186,7 @@ Feature: Psalm module
Scenario: Escaping pipes in regexps
Given I have the following code
"""
/** @api */
class CC extends PPP {}
"""
When I run Psalm
Expand All @@ -196,6 +198,7 @@ Feature: Psalm module
Scenario: Using backslashes in regexps
Given I have the following code
"""
/** @api */
class C extends PPP {}
"""
When I run Psalm
Expand Down