-
Notifications
You must be signed in to change notification settings - Fork 471
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes phpstan/phpstan#4829 Closes phpstan/phpstan#4844 Closes phpstan/phpstan#3784 Closes phpstan/phpstan#3700 Closes phpstan/phpstan#4848 Closes phpstan/phpstan#5162
- Loading branch information
1 parent
4a3ffab
commit 3c3ea2f
Showing
10 changed files
with
209 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace Bug3700; | ||
|
||
class HelloWorld | ||
{ | ||
public function errorWithExtension(): void | ||
{ | ||
$filePath = 'somefile.txt'; | ||
$pathInfo = pathinfo($filePath); | ||
$extension = empty($pathInfo['extension']) ? '' : '.' . $pathInfo['extension']; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace Bug3784; | ||
|
||
class HelloWorld | ||
{ | ||
public function sayHello(string $value): void | ||
{ | ||
$parsedValue = parse_url($value); | ||
|
||
if (false === $parsedValue) { | ||
return; | ||
} | ||
|
||
foreach (['host'] as $key) { | ||
if (empty($parsedValue[$key])) { | ||
return; | ||
} | ||
} | ||
|
||
var_dump($parsedValue['host']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Bug4829; | ||
|
||
class Test | ||
{ | ||
// PHPStan 0.12.83 level 7 error: | ||
// 26 Offset 'cat3' does not exist on array('cat1' => 'blah1', 'cat2' => 'blah2', ?'cat3' => 'blah3'). | ||
public function stan() : void | ||
{ | ||
$ret = []; | ||
|
||
// if $result has 1 element, the error does not occur | ||
// if $result is [], the error occurs | ||
$result = ["val1", "val2"]; | ||
|
||
foreach ($result as $val) { | ||
// if I replace $val with a string, the error does not occur | ||
//$val = "test"; | ||
|
||
// if I remove one assignment, the error does not occur | ||
$ret[$val]['cat1'] = "blah1"; | ||
$ret[$val]['cat2'] = "blah2"; | ||
$ret[$val]['cat3'] = 'blah3'; | ||
|
||
$t1 = $ret[$val]['cat1']; | ||
$t2 = $ret[$val]['cat2']; | ||
$t3 = $ret[$val]['cat3']; // error occurs here | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
namespace Bug5162; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
class Foo | ||
{ | ||
|
||
|
||
/** | ||
* @return array<string,string|array<string>> | ||
*/ | ||
function Get() | ||
{ | ||
switch ( rand(1,3) ) | ||
{ | ||
case 1: | ||
return ['a' => 'val']; | ||
case 2: | ||
return ['a' => '1']; | ||
case 3: | ||
return ['a' => []]; | ||
} | ||
return []; | ||
} | ||
|
||
public function doFoo(): void | ||
{ | ||
// This variant works | ||
$result1 = $this->Get(); | ||
if ( ! array_key_exists('a', $result1)) | ||
{ | ||
exit(1); | ||
} | ||
if ( ! is_numeric( $result1['a'] ) ) | ||
{ | ||
exit(1); | ||
} | ||
$val = (float) $result1['a']; | ||
} | ||
|
||
public function doBar(): void | ||
{ | ||
// This variant doesn't work .. but is logically identical | ||
$result2 = $this->Get(); | ||
if ( array_key_exists('a',$result2) && ! is_numeric( $result2['a'] ) ) | ||
{ | ||
exit(1); | ||
} | ||
if ( ! array_key_exists('a', $result2) ) | ||
{ | ||
exit(1); | ||
} | ||
$val = (float) $result2['a']; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace Bug4848; | ||
|
||
function (): void { | ||
$maxBigintInMysql = '18446744073709551615'; | ||
if ($maxBigintInMysql === (string)(int)$maxBigintInMysql) { | ||
echo 'same: ' . (string)(int)$maxBigintInMysql; | ||
} else { | ||
echo 'different: ' .(string)(int)$maxBigintInMysql; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace Bug4844; | ||
|
||
class HelloWorld | ||
{ | ||
/** | ||
* Updates a attribute and saves the record. | ||
* | ||
* @param string $name | ||
* @param string $value | ||
* | ||
* @return bool | ||
*/ | ||
public function update_attribute($name, $value = '') | ||
{ | ||
return $this->update_attributes([ | ||
$name => $value, | ||
]); | ||
} | ||
|
||
/** | ||
* Updates as an array given attributes and saves the record. | ||
* | ||
* @param non-empty-array<string, mixed> $attributes | ||
* | ||
* @return bool | ||
*/ | ||
public function update_attributes($attributes) | ||
{ | ||
return true; | ||
} | ||
} |