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
4 changes: 4 additions & 0 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ jobs:
mv src/Foo.php.orig src/Foo.php
echo -n > phpstan-baseline.neon
../../bin/phpstan -vvv
- script: |
cd e2e/bug-14514
composer install
../../bin/phpstan analyze bug-14515.php
- script: |
cd e2e/bug10449
../../bin/phpstan analyze
Expand Down
1 change: 1 addition & 0 deletions e2e/bug-14514/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/vendor
7 changes: 7 additions & 0 deletions e2e/bug-14514/autoloader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

spl_autoload_register(function ($class) {
if ($class === 'index') {
throw new LogicException("Autoloader should not be called for 'index'");
}
});
3 changes: 3 additions & 0 deletions e2e/bug-14514/bug-14515.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

throw new Exception("ERROR: " . 'index');
5 changes: 5 additions & 0 deletions e2e/bug-14514/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"autoload": {
"files": [ "autoloader.php" ]
}
}
18 changes: 18 additions & 0 deletions e2e/bug-14514/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@
$impurePoints = [];

$exprType = $scope->getType($expr);
$toStringMethod = $scope->getMethodReflection($exprType, '__toString');

$toStringMethod = null;
if (!$exprType->isObject()->no()) {

Check warning on line 33 in src/Analyser/ExprHandler/Helper/ImplicitToStringCallHelper.php

View workflow job for this annotation

GitHub Actions / Mutation Testing (8.4, ubuntu-latest)

Escaped Mutant for Mutator "PHPStan\Infection\TrinaryLogicMutator": @@ @@ $exprType = $scope->getType($expr); $toStringMethod = null; - if (!$exprType->isObject()->no()) { + if ($exprType->isObject()->yes()) { $toStringMethod = $scope->getMethodReflection($exprType, '__toString'); } if ($toStringMethod === null) {

Check warning on line 33 in src/Analyser/ExprHandler/Helper/ImplicitToStringCallHelper.php

View workflow job for this annotation

GitHub Actions / Mutation Testing (8.3, ubuntu-latest)

Escaped Mutant for Mutator "PHPStan\Infection\TrinaryLogicMutator": @@ @@ $exprType = $scope->getType($expr); $toStringMethod = null; - if (!$exprType->isObject()->no()) { + if ($exprType->isObject()->yes()) { $toStringMethod = $scope->getMethodReflection($exprType, '__toString'); } if ($toStringMethod === null) {
$toStringMethod = $scope->getMethodReflection($exprType, '__toString');
}
if ($toStringMethod === null) {
return new ExpressionResult(
$scope,
Expand Down
5 changes: 5 additions & 0 deletions tests/PHPStan/Rules/Pure/PureFunctionRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,9 @@ public function testBug14504(): void
$this->analyse([__DIR__ . '/data/bug-14504.php'], []);
}

public function testBug14511(): void
{
$this->analyse([__DIR__ . '/data/bug-14511.php'], []);
}

}
6 changes: 6 additions & 0 deletions tests/PHPStan/Rules/Pure/PureMethodRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -383,4 +383,10 @@ public function testBug14504(): void
$this->analyse([__DIR__ . '/data/bug-14504-method.php'], []);
}

public function testBug14511(): void
{
$this->treatPhpDocTypesAsCertain = true;
$this->analyse([__DIR__ . '/data/bug-14511-method.php'], []);
}

}
47 changes: 47 additions & 0 deletions tests/PHPStan/Rules/Pure/data/bug-14511-method.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php declare(strict_types = 1);

namespace Bug14511Method;

class Foo
{

/**
* @phpstan-pure
* @template T of mixed
* @param T $val
*/
public function testStringCast(mixed $val): ?string
{
if (is_int($val)) {
return (string) $val;
}
return null;
}

/**
* @phpstan-pure
* @template T of mixed
* @param T $val
*/
public function testStringConcat(mixed $val): ?string
{
if (is_int($val)) {
return 'value: ' . $val;
}
return null;
}

/**
* @phpstan-pure
* @template T of mixed
* @param T $val
*/
public function testEmptyNonArray(mixed $val): ?string
{
if (empty($val) && !\is_array($val)) {
return (string) $val;
}
return null;
}

}
75 changes: 75 additions & 0 deletions tests/PHPStan/Rules/Pure/data/bug-14511.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php declare(strict_types = 1);

namespace Bug14511;

/**
* @phpstan-pure
* @template T of mixed
* @param T $val
*/
function testStringCast(mixed $val): ?string {
if (is_int($val)) {
return (string) $val;
}
return null;
}

/**
* @phpstan-pure
* @template T of mixed
* @param T $val
*/
function testStringConcat(mixed $val): ?string {
if (is_int($val)) {
return 'value: ' . $val;
}
return null;
}

/**
* @phpstan-pure
* @template T of mixed
* @param T $val
*/
function testFloatCast(mixed $val): ?string {
if (is_float($val)) {
return (string) $val;
}
return null;
}

/**
* @phpstan-pure
* @template T of mixed
* @param T $val
*/
function testBoolCast(mixed $val): ?string {
if (is_bool($val)) {
return (string) $val;
}
return null;
}

/**
* @phpstan-pure
* @template T of mixed
* @param T $val
*/
function testStringVal(mixed $val): ?string {
if (is_string($val)) {
return (string) $val;
}
return null;
}

/**
* @phpstan-pure
* @template T of mixed
* @param T $val
*/
function testEmptyNonArray(mixed $val): ?string {
if (empty($val) && !\is_array($val)) {
return (string) $val;
}
return null;
}
Loading