Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix parameter of strval, intval and floatval #1005

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Khartir wants to merge 6 commits into phpstan:1.5.x
base: 1.5.x
Choose a base branch
Loading
from Khartir:fix-strval-parameter
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
allow casting resource to float
  • Loading branch information
Khartir committed Feb 18, 2022
commit 0251dca9033e8f2078d3c5bfaae9a16595f1abcc
2 changes: 1 addition & 1 deletion src/Type/ResourceType.php
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function toInteger(): Type

public function toFloat(): Type
{
return new ErrorType();
return new FloatType();
}

public function toArray(): Type
Expand Down
61 changes: 29 additions & 32 deletions tests/PHPStan/Analyser/AnalyserIntegrationTest.php
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -544,44 +544,41 @@ public function testBug6501(): void
public function testTypevalFamilyFunctionParameters(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/typeval-functions.php');
$this->assertCount(15, $errors);
$this->assertCount(14, $errors);

$this->assertSame('Cannot cast array{} to string.', $errors[0]->getMessage());
$this->assertSame(19, $errors[0]->getLine());
$this->assertSame('Parameter #1 $value of function strval expects bool|float|int|resource|string|null, array given.', $errors[1]->getMessage());
$this->assertSame(20, $errors[1]->getLine());

$this->assertSame('Cannot cast resource to float.', $errors[2]->getMessage());
$this->assertSame(65, $errors[2]->getLine());

$this->assertSame('Cannot cast stdClass to string.', $errors[3]->getMessage());
$this->assertSame(79, $errors[3]->getLine());
$this->assertSame('Parameter #1 $value of function strval expects bool|float|int|resource|string|null, stdClass given.', $errors[4]->getMessage());
$this->assertSame(80, $errors[4]->getLine());

$this->assertSame('Cannot cast stdClass to int.', $errors[5]->getMessage());
$this->assertSame(82, $errors[5]->getLine());
$this->assertSame('Parameter #1 $value of function intval expects array|bool|float|int|resource|string|null, stdClass given.', $errors[6]->getMessage());
$this->assertSame(83, $errors[6]->getLine());

$this->assertSame('Cannot cast stdClass to float.', $errors[7]->getMessage());
$this->assertSame(85, $errors[7]->getLine());
$this->assertSame('Parameter #1 $value of function floatval expects array|bool|float|int|resource|string|null, stdClass given.', $errors[8]->getMessage());
$this->assertSame(86, $errors[8]->getLine());
$this->assertSame('Parameter #1 $value of function doubleval expects array|bool|float|int|resource|string|null, stdClass given.', $errors[9]->getMessage());
$this->assertSame(87, $errors[9]->getLine());

$this->assertSame('Cannot cast class@anonymous/tests/PHPStan/Analyser/data/typeval-functions.php:10 to int.', $errors[10]->getMessage());
$this->assertSame(92, $errors[10]->getLine());
$this->assertSame('Parameter #1 $value of function intval does not accept object, class@anonymous/tests/PHPStan/Analyser/data/typeval-functions.php:10 given.', $errors[11]->getMessage());
$this->assertSame(93, $errors[11]->getLine());

$this->assertSame('Cannot cast class@anonymous/tests/PHPStan/Analyser/data/typeval-functions.php:10 to float.', $errors[12]->getMessage());
$this->assertSame(95, $errors[12]->getLine());
$this->assertSame('Parameter #1 $value of function floatval does not accept object, class@anonymous/tests/PHPStan/Analyser/data/typeval-functions.php:10 given.', $errors[13]->getMessage());
$this->assertSame(96, $errors[13]->getLine());
$this->assertSame('Parameter #1 $value of function doubleval does not accept object, class@anonymous/tests/PHPStan/Analyser/data/typeval-functions.php:10 given.', $errors[14]->getMessage());
$this->assertSame(97, $errors[14]->getLine());
$this->assertSame('Cannot cast stdClass to string.', $errors[2]->getMessage());
$this->assertSame(79, $errors[2]->getLine());
$this->assertSame('Parameter #1 $value of function strval expects bool|float|int|resource|string|null, stdClass given.', $errors[3]->getMessage());
$this->assertSame(80, $errors[3]->getLine());

$this->assertSame('Cannot cast stdClass to int.', $errors[4]->getMessage());
$this->assertSame(82, $errors[4]->getLine());
$this->assertSame('Parameter #1 $value of function intval expects array|bool|float|int|resource|string|null, stdClass given.', $errors[5]->getMessage());
$this->assertSame(83, $errors[5]->getLine());

$this->assertSame('Cannot cast stdClass to float.', $errors[6]->getMessage());
$this->assertSame(85, $errors[6]->getLine());
$this->assertSame('Parameter #1 $value of function floatval expects array|bool|float|int|resource|string|null, stdClass given.', $errors[7]->getMessage());
$this->assertSame(86, $errors[7]->getLine());
$this->assertSame('Parameter #1 $value of function doubleval expects array|bool|float|int|resource|string|null, stdClass given.', $errors[8]->getMessage());
$this->assertSame(87, $errors[8]->getLine());

$this->assertSame('Cannot cast class@anonymous/tests/PHPStan/Analyser/data/typeval-functions.php:10 to int.', $errors[9]->getMessage());
$this->assertSame(92, $errors[9]->getLine());
$this->assertSame('Parameter #1 $value of function intval does not accept object, class@anonymous/tests/PHPStan/Analyser/data/typeval-functions.php:10 given.', $errors[10]->getMessage());
$this->assertSame(93, $errors[10]->getLine());

$this->assertSame('Cannot cast class@anonymous/tests/PHPStan/Analyser/data/typeval-functions.php:10 to float.', $errors[11]->getMessage());
$this->assertSame(95, $errors[11]->getLine());
$this->assertSame('Parameter #1 $value of function floatval does not accept object, class@anonymous/tests/PHPStan/Analyser/data/typeval-functions.php:10 given.', $errors[12]->getMessage());
$this->assertSame(96, $errors[12]->getLine());
$this->assertSame('Parameter #1 $value of function doubleval does not accept object, class@anonymous/tests/PHPStan/Analyser/data/typeval-functions.php:10 given.', $errors[13]->getMessage());
$this->assertSame(97, $errors[13]->getLine());
}

/**
Expand Down

AltStyle によって変換されたページ (->オリジナル) /