-
-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
62 additions
and
5 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 |
---|---|---|
|
@@ -170,14 +170,19 @@ public static function createObject(string $class, array $props): object | |
|
||
public static function validateType(?string $type, bool &$nullable): ?string | ||
{ | ||
$nullable = false; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
krizdavid
|
||
if ($type === '' || $type === null) { | ||
return null; | ||
} | ||
|
||
if (!preg_match('#(?: | ||
\?[\w\\\\]+| | ||
[\w\\\\]+ (?: (&[\w\\\\]+)* | (\|[\w\\\\]+)* ) | ||
)()$#xAD', $type)) { | ||
if (!preg_match(<<<'XX' | ||
~(?n) | ||
( | ||
\?? (?<type> [\w\\]+)| | ||
(?<intersection> (?&type) (& (?&type))+ )| | ||
(?<upart> (?&type) | \( (?&intersection) \) ) (\| (?&upart) )+ | ||
)$~xAD | ||
XX, $type)) { | ||
throw new Nette\InvalidArgumentException("Value '$type' is not valid type."); | ||
} | ||
|
||
|
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,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Nette\PhpGenerator\Helpers; | ||
use Tester\Assert; | ||
|
||
|
||
require __DIR__ . '/../bootstrap.php'; | ||
|
||
|
||
$foo = false; | ||
Assert::null(Helpers::validateType('', $foo)); | ||
Assert::null(Helpers::validateType(null, $foo)); | ||
Assert::same('Foo', Helpers::validateType('Foo', $foo)); | ||
Assert::same('Foo\Bar', Helpers::validateType('Foo\Bar', $foo)); | ||
Assert::same('\Foo\Bar', Helpers::validateType('\Foo\Bar', $foo)); | ||
Assert::same('Foo', Helpers::validateType('?Foo', $foo)); | ||
Assert::true($foo); | ||
Assert::same('Foo|Bar', Helpers::validateType('Foo|Bar', $foo)); | ||
Assert::same('Foo&Bar\X', Helpers::validateType('Foo&Bar\X', $foo)); | ||
Assert::same('(Foo&Bar\X)|Baz', Helpers::validateType('(Foo&Bar\X)|Baz', $foo)); | ||
Assert::same('Abc\C|(Abc\X&Abc\D)|null', Helpers::validateType('Abc\C|(Abc\X&Abc\D)|null', $foo)); | ||
|
||
Assert::exception( | ||
fn() => Helpers::validateType('-', $foo), | ||
Nette\InvalidArgumentException::class, | ||
); | ||
|
||
Assert::exception( | ||
fn() => Helpers::validateType('?Foo|Bar', $foo), | ||
Nette\InvalidArgumentException::class, | ||
); | ||
|
||
Assert::exception( | ||
fn() => Helpers::validateType('(Foo)', $foo), | ||
Nette\InvalidArgumentException::class, | ||
); | ||
|
||
Assert::exception( | ||
fn() => Helpers::validateType('(Foo&Bar)', $foo), | ||
Nette\InvalidArgumentException::class, | ||
); |
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 |
---|---|---|
@@ -1,5 +1,8 @@ | ||
readonly class Class13 | ||
{ | ||
public function func(C|(X&D)|null $foo): (A&B)|null | ||
{ | ||
} | ||
} | ||
|
||
trait Trait13 | ||
|
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 |
---|---|---|
|
@@ -6,6 +6,9 @@ | |
|
||
readonly class Class13 | ||
{ | ||
public function func(C|(X&D)|null $foo): (A&B)|null | ||
{ | ||
} | ||
} | ||
|
||
|
||
|
@dg tohle není moc dobře ne ? ty předáš parametr $nullable jako referenci a pak to přebouchneš na false ?