Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Specify types on match() condition correctly
- Loading branch information
1 parent
e55a83f
commit 149a1e7
Showing
5 changed files
with
77 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php declare(strict_types = 1); // lint >= 8.0 | ||
|
||
namespace Bug10974; | ||
|
||
function non(): void {} | ||
function single(string $str): void {} | ||
/** @param non-empty-array<string> $strs */ | ||
function multiple(array $strs): void {} | ||
|
||
/** @param array<string> $arr */ | ||
function test(array $arr): void | ||
{ | ||
match (count($arr)) | ||
{ | ||
0 => non(), | ||
1 => single(reset($arr)), | ||
default => multiple($arr) | ||
}; | ||
|
||
if (empty($arr)) { | ||
non(); | ||
} elseif (count($arr) === 1) { | ||
single(reset($arr)); | ||
} else { | ||
multiple($arr); | ||
} | ||
} |
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,20 @@ | ||
<?php declare(strict_types = 1); // lint >= 8.0 | ||
|
||
class TotpEnrollment | ||
{ | ||
public bool $confirmed; | ||
} | ||
|
||
class User | ||
{ | ||
public ?TotpEnrollment $totpEnrollment; | ||
} | ||
|
||
function () { | ||
$user = new User(); | ||
|
||
return match ($user->totpEnrollment === null) { | ||
true => false, | ||
false => $user->totpEnrollment->confirmed, | ||
}; | ||
}; |