Skip to content
Open
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
5 changes: 4 additions & 1 deletion src/Type/ObjectType.php
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,10 @@

public function toNumber(): Type
{
if ($this->isInstanceOf('SimpleXMLElement')->yes()) {
if (
$this->isInstanceOf('SimpleXMLElement')->yes()

Check warning on line 756 in src/Type/ObjectType.php

View workflow job for this annotation

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

Escaped Mutant for Mutator "PHPStan\Infection\TrinaryLogicMutator": @@ @@ public function toNumber(): Type { if ( - $this->isInstanceOf('SimpleXMLElement')->yes() + !$this->isInstanceOf('SimpleXMLElement')->no() || $this->isInstanceOf('GMP')->yes() ) { return new UnionType([

Check warning on line 756 in src/Type/ObjectType.php

View workflow job for this annotation

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

Escaped Mutant for Mutator "PHPStan\Infection\TrinaryLogicMutator": @@ @@ public function toNumber(): Type { if ( - $this->isInstanceOf('SimpleXMLElement')->yes() + !$this->isInstanceOf('SimpleXMLElement')->no() || $this->isInstanceOf('GMP')->yes() ) { return new UnionType([
|| $this->isInstanceOf('GMP')->yes()

Check warning on line 757 in src/Type/ObjectType.php

View workflow job for this annotation

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

Escaped Mutant for Mutator "PHPStan\Infection\TrinaryLogicMutator": @@ @@ { if ( $this->isInstanceOf('SimpleXMLElement')->yes() - || $this->isInstanceOf('GMP')->yes() + || !$this->isInstanceOf('GMP')->no() ) { return new UnionType([ new FloatType(),

Check warning on line 757 in src/Type/ObjectType.php

View workflow job for this annotation

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

Escaped Mutant for Mutator "PHPStan\Infection\TrinaryLogicMutator": @@ @@ { if ( $this->isInstanceOf('SimpleXMLElement')->yes() - || $this->isInstanceOf('GMP')->yes() + || !$this->isInstanceOf('GMP')->no() ) { return new UnionType([ new FloatType(),
) {
return new UnionType([
new FloatType(),
new IntegerType(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,36 @@ public function testBug11883(): void
]);
}

public function testBug13775(): void
{
$this->analyse([__DIR__ . '/data/bug-13775.php'], $this->hackPhp74ErrorMessages([
[
'Parameter #1 $array of function array_product expects an array of values castable to number, array<int, string> given.',
13,
],
[
'Parameter #1 $array of function array_product expects an array of values castable to number, array<int, string> given.',
19,
],
[
'Parameter #1 $array of function array_product expects an array of values castable to number, array<int, string> given.',
22,
],
[
'Parameter #1 $array of function array_product expects an array of values castable to number, array<int, string> given.',
25,
],
[
'Parameter #1 $array of function array_product expects an array of values castable to number, array<int, array> given.',
28,
],
[
'Parameter #1 $array of function array_product expects an array of values castable to number, array<int, stdClass> given.',
31,
],
]));
}

public function testBug12146(): void
{
$this->analyse([__DIR__ . '/data/bug-12146.php'], $this->hackPhp74ErrorMessages([
Expand Down
34 changes: 34 additions & 0 deletions tests/PHPStan/Rules/Functions/data/bug-13775.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php declare(strict_types = 1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue 13775 also talks about array_sum which is not yet covered in tests


$a = [null];
echo 'null, valid cast: ' . array_product($a) . "\n\n";

$a = [false];
echo 'false, valid cast: ' . array_product($a) . "\n\n";

$a = [true];
echo 'true, valid cast: ' . array_product($a) . "\n\n";

$a = [''];
echo 'empty string, invalid cast: ' . array_product($a) . "\n\n";

$a = ['42.5'];
echo 'string of a float, valid cast: ' . array_product($a) . "\n\n";

$a = ['42,5'];
echo 'string of comma-separated float, valid cast but not desirable (discards trailing chars): ' . array_product($a) . "\n\n";

$a = ['42a'];
echo 'string of int with trailing alpha char, valid cast but not desirable (discards trailing chars): ' . array_product($a) . "\n\n";

$a = ['a42'];
echo 'string of int with leading alpha char, invalid cast: ' . array_product($a) . "\n\n";

$a = [[]];
echo 'array, invalid cast: ' . array_product($a) . "\n\n";

$a = [new stdClass()];
echo 'class that does not auto-cast, invalid cast: ' . array_product($a) . "\n\n";

$a = [gmp_init(42)];
echo 'gmp, valid cast: ' . array_product($a) . "\n\n";
Loading