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
implemented constant-type inference in ImplodeFunctionReturnTypeExtension #991
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,9 +7,9 @@ | |
class HelloWorld | ||
{ | ||
|
||
protected function foo(string $message): void | ||
protected function foo(string $message, string $x): void | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. adjusted the existing test, so it still leads to the same result as before this PR. |
||
{ | ||
$header = sprintf('%s-%s', '', implode('-', ['x'])); | ||
$header = sprintf('%s-%s', '', implode('-', [$x])); | ||
|
||
assertType('non-empty-string', $header); | ||
assertType('non-empty-array<non-empty-string, string>', [$header => $message]); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace ImplodeFunctionReturn; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
class Foo | ||
{ | ||
const X = 'x'; | ||
const ONE = 1; | ||
|
||
public function constants() { | ||
assertType("'12345'", implode(['12', '345'])); | ||
|
||
assertType("'12345'", implode('', ['12', '345'])); | ||
assertType("'12345'", join('', ['12', '345'])); | ||
|
||
assertType("'12,345'", implode(',', ['12', '345'])); | ||
assertType("'12,345'", join(',', ['12', '345'])); | ||
|
||
assertType("'x,345'", join(',', [self::X, '345'])); | ||
assertType("'1,345'", join(',', [self::ONE, '345'])); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -206,10 +206,10 @@ public function doFoo4(string $s, array $nonEmptyArrayWithNonEmptyStrings): void | |
assertType('non-empty-string', implode($nonEmptyArrayWithNonEmptyStrings)); | ||
} | ||
|
||
public function sayHello(): void | ||
public function sayHello(int $i): void | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. adjusted the existing test, so it still leads to the same result as before this PR. |
||
{ | ||
// coming from issue #5291 | ||
$s = array(1, 2); | ||
$s = array(1, $i); | ||
|
||
assertType('non-empty-string', implode("a", $s)); | ||
} | ||
|
@@ -227,10 +227,10 @@ public function nonE($glue, array $a) | |
assertType('non-empty-string', implode($glue, $a)); | ||
} | ||
|
||
public function sayHello2(): void | ||
public function sayHello2(int $i): void | ||
{ | ||
// coming from issue #5291 | ||
$s = array(1, 2); | ||
$s = array(1, $i); | ||
|
||
assertType('non-empty-string', join("a", $s)); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this code was duplicated in the extension. de-duplicated the existing logic with the first commit with 180b2af