-
Notifications
You must be signed in to change notification settings - Fork 426
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix subtracting types from union template types
- Loading branch information
1 parent
8a6d6a5
commit ec957a9
Showing
3 changed files
with
74 additions
and
3 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,63 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Bug9939; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
enum Combinator | ||
{ | ||
case NEXT_SIBLING; | ||
case CHILD; | ||
case FOLLOWING_SIBLING; | ||
|
||
public function getText(): string | ||
{ | ||
return match ($this) { | ||
self::NEXT_SIBLING => '+', | ||
self::CHILD => '>', | ||
self::FOLLOWING_SIBLING => '~', | ||
}; | ||
} | ||
} | ||
|
||
/** | ||
* @template T of string|\Stringable|array<string|\Stringable>|Combinator|null | ||
*/ | ||
class CssValue | ||
{ | ||
/** | ||
* @param T $value | ||
*/ | ||
public function __construct(private readonly mixed $value) | ||
{ | ||
} | ||
|
||
/** | ||
* @return T | ||
*/ | ||
public function getValue(): mixed | ||
{ | ||
return $this->value; | ||
} | ||
|
||
public function __toString(): string | ||
{ | ||
assertType('T of array<string|Stringable>|Bug9939\Combinator|string|Stringable|null (class Bug9939\CssValue, argument)', $this->value); | ||
|
||
if ($this->value instanceof Combinator) { | ||
assertType('T of Bug9939\Combinator (class Bug9939\CssValue, argument)', $this->value); | ||
return $this->value->getText(); | ||
} | ||
|
||
assertType('T of array<string|Stringable>|string|Stringable|null (class Bug9939\CssValue, argument)', $this->value); | ||
|
||
if (\is_array($this->value)) { | ||
assertType('T of array<string|Stringable> (class Bug9939\CssValue, argument)', $this->value); | ||
return implode($this->value); | ||
} | ||
|
||
assertType('T of string|Stringable|null (class Bug9939\CssValue, argument)', $this->value); | ||
|
||
return (string) $this->value; | ||
} | ||
} |