-
-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Printer: print brace on next line when method/function has typehint
- Loading branch information
Showing
7 changed files
with
98 additions
and
20 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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Nette\PhpGenerator\Printer; | ||
use Tester\Assert; | ||
|
||
require __DIR__ . '/../bootstrap.php'; | ||
|
||
|
||
$printer = new Printer; | ||
$function = new Nette\PhpGenerator\GlobalFunction('func'); | ||
$function | ||
->setReturnType('stdClass') | ||
->setBody("func(); \r\nreturn 123;") | ||
->addParameter('var') | ||
->setType('stdClass'); | ||
|
||
Assert::match(<<<'XX' | ||
function func(stdClass $var): stdClass | ||
{ | ||
func(); | ||
return 123; | ||
} | ||
|
||
XX, $printer->printFunction($function)); | ||
|
||
|
||
$function = new Nette\PhpGenerator\GlobalFunction('multi'); | ||
$function->addParameter('foo') | ||
->addAttribute('Foo'); | ||
|
||
Assert::match(<<<'XX' | ||
function multi( | ||
#[Foo] $foo, | ||
) { | ||
} | ||
|
||
XX, $printer->printFunction($function)); | ||
|
||
|
||
$function = new Nette\PhpGenerator\GlobalFunction('multiType'); | ||
$function | ||
->setReturnType('array') | ||
->addParameter('foo') | ||
->addAttribute('Foo'); | ||
|
||
Assert::match(<<<'XX' | ||
function multiType( | ||
#[Foo] $foo, | ||
): array | ||
{ | ||
} | ||
|
||
XX, $printer->printFunction($function)); |
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 |
---|---|---|
|
@@ -18,7 +18,8 @@ class A implements A, C | |
array $d, | ||
?callable $e, | ||
C|string $f, | ||
): static|A { | ||
): static|A | ||
{ | ||
} | ||
} | ||
|
||
|
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 was deleted.
Oops, something went wrong.
It would be nice if the PsrPrinter could still follow the PSR codestyle: https://www.php-fig.org/psr/psr-12/ (on a single line regardless of return type).
Or if that could be adjusted in an extended class.