Skip to content

Commit

Permalink
Prevent running code
Browse files Browse the repository at this point in the history
  • Loading branch information
rvanvelzen committed Apr 28, 2022
1 parent d6545a9 commit 81b7b66
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 28 deletions.
8 changes: 4 additions & 4 deletions tests/PHPStan/Analyser/AnalyserIntegrationTest.php
Expand Up @@ -780,13 +780,13 @@ public function testDiscussion7124(): void
$errors = $this->runAnalyse(__DIR__ . '/data/discussion-7124.php');
$this->assertCount(4, $errors);
$this->assertSame('Parameter #2 $callback of function Discussion7124\filter expects callable(bool, int): bool, Closure(int, bool): bool given.', $errors[0]->getMessage());
$this->assertSame(37, $errors[0]->getLine());
$this->assertSame(38, $errors[0]->getLine());
$this->assertSame('Parameter #2 $callback of function Discussion7124\filter expects callable(bool, int): bool, Closure(int): bool given.', $errors[1]->getMessage());
$this->assertSame(44, $errors[1]->getLine());
$this->assertSame(45, $errors[1]->getLine());
$this->assertSame('Parameter #2 $callback of function Discussion7124\filter expects callable(int): bool, Closure(bool): bool given.', $errors[2]->getMessage());
$this->assertSame(51, $errors[2]->getLine());
$this->assertSame(52, $errors[2]->getLine());
$this->assertSame('Parameter #2 $callback of function Discussion7124\filter expects callable(bool): bool, Closure(int): bool given.', $errors[3]->getMessage());
$this->assertSame(58, $errors[3]->getLine());
$this->assertSame(59, $errors[3]->getLine());
}

/**
Expand Down
50 changes: 26 additions & 24 deletions tests/PHPStan/Analyser/data/discussion-7124.php
Expand Up @@ -31,30 +31,32 @@ function filter(array $array, ?callable $callback = null, int $mode = ARRAY_FILT
: array_filter($array);
}

// This one does fail, as both the value + key is asked and the key + value is used
filter(
[false, true, false],
static fn (int $key, bool $value): bool => 0 === $key % 2 && $value,
mode: ARRAY_FILTER_USE_BOTH,
);
function () {
// This one does fail, as both the value + key is asked and the key + value is used
filter(
[false, true, false],
static fn (int $key, bool $value): bool => 0 === $key % 2 && $value,
mode: ARRAY_FILTER_USE_BOTH,
);

// This one should fail, as both the value + key is asked but only the key is used
filter(
[false, true, false],
static fn (int $key): bool => 0 === $key % 2,
mode: ARRAY_FILTER_USE_BOTH,
);
// This one should fail, as both the value + key is asked but only the key is used
filter(
[false, true, false],
static fn (int $key): bool => 0 === $key % 2,
mode: ARRAY_FILTER_USE_BOTH,
);

// This one should fail, as only the key is asked but the value is used
filter(
[false, true, false],
static fn (bool $value): bool => $value,
mode: ARRAY_FILTER_USE_KEY,
);
// This one should fail, as only the key is asked but the value is used
filter(
[false, true, false],
static fn (bool $value): bool => $value,
mode: ARRAY_FILTER_USE_KEY,
);

// This one should fail, as only the value is asked but the key is used
filter(
[false, true, false],
static fn (int $key): bool => 0 === $key % 2,
mode: 0,
);
// This one should fail, as only the value is asked but the key is used
filter(
[false, true, false],
static fn (int $key): bool => 0 === $key % 2,
mode: 0,
);
};

0 comments on commit 81b7b66

Please sign in to comment.