-
Notifications
You must be signed in to change notification settings - Fork 476
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix wrong tip about returning a list
Closes phpstan/phpstan#10077
- Loading branch information
1 parent
7f87272
commit 00adfaa
Showing
7 changed files
with
129 additions
and
12 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
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,57 @@ | ||
<?php | ||
|
||
namespace Bug10077; | ||
|
||
interface MediaQueryMergeResult | ||
{ | ||
} | ||
|
||
|
||
enum MediaQuerySingletonMergeResult implements MediaQueryMergeResult | ||
{ | ||
case empty; | ||
case unrepresentable; | ||
} | ||
|
||
// In actual code, this is a final class implementing its methods | ||
abstract class CssMediaQuery implements MediaQueryMergeResult | ||
{ | ||
abstract public function merge(CssMediaQuery $other): MediaQueryMergeResult; | ||
} | ||
|
||
|
||
/** | ||
* Returns a list of queries that selects for contexts that match both | ||
* $queries1 and $queries2. | ||
* | ||
* Returns the empty list if there are no contexts that match both $queries1 | ||
* and $queries2, or `null` if there are contexts that can't be represented | ||
* by media queries. | ||
* | ||
* @param CssMediaQuery[] $queries1 | ||
* @param CssMediaQuery[] $queries2 | ||
* | ||
* @return list<CssMediaQuery>|null | ||
*/ | ||
function mergeMediaQueries(array $queries1, array $queries2): ?array | ||
{ | ||
$queries = []; | ||
|
||
foreach ($queries1 as $query1) { | ||
foreach ($queries2 as $query2) { | ||
$result = $query1->merge($query2); | ||
|
||
if ($result === MediaQuerySingletonMergeResult::empty) { | ||
continue; | ||
} | ||
|
||
if ($result === MediaQuerySingletonMergeResult::unrepresentable) { | ||
return null; | ||
} | ||
|
||
$queries[] = $result; | ||
} | ||
} | ||
|
||
return $queries; | ||
} |
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,34 @@ | ||
<?php | ||
|
||
namespace WrongListTip; | ||
|
||
interface Foo | ||
{ | ||
|
||
} | ||
|
||
interface Bar | ||
{ | ||
|
||
} | ||
|
||
class Test | ||
{ | ||
|
||
/** | ||
* @return list<Foo> | ||
*/ | ||
public function doFoo(): array | ||
{ | ||
return $this->listOfBars(); | ||
} | ||
|
||
/** | ||
* @return list<Bar> | ||
*/ | ||
public function listOfBars(): array | ||
{ | ||
return []; | ||
} | ||
|
||
} |
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