You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<?php$namespace = new \Nette\PhpGenerator\PhpNamespace('Foo');
$class = $namespace->addClass('Bar')->addTrait('SomeTrait');
$file = new \Nette\PhpGenerator\PhpFile();
$file->addNamespace($namespace);
echo (new \Nette\PhpGenerator\Printer())->printFile($file);
Result:
<?phpnamespaceFoo;
class Bar
{
use \SomeTrait;
}
Desired result:
<?phpnamespaceFoo;
class Bar
{
/** @use \SomeTrait<\Carbon\CarbonImmutable> */use \SomeTrait;
}
Trait for use case:
<?php/** @template T of \DateTimeInterface */trait SomeTrait
{
/** @return T */publicfunctioncreateDate(): \DateTimeInterface
{
return \Carbon\CarbonImmutable::now();
}
}
Activity
dg commentedon Sep 21, 2021
Can you describe it better?
InvisibleSmiley commentedon Sep 21, 2021
Example code:
Result:
Desired result:
Trait for use case:
dg commentedon Sep 21, 2021
The ideal would be something like
but
addTrait()returnsstaticand to change that would be a big BC break…Maybe add a new method
useTrait()...InvisibleSmiley commentedon Sep 21, 2021
I'd rather say adapt addTrait to accept either a string (behavior like now) or a class that wraps the name and PHPDoc, like so:
"use Trait" can have comments [Closes #90]
"use Trait" can have comments [Closes #90]
"use Trait" can have comments [Closes #90]
"use Trait" can have comments [Closes #90]
dg commentedon Sep 21, 2021
It's working now. I added the
trueparameter and then it returns theTraitUseobject:"use Trait" can have comments [Closes #90]
"use Trait" can have comments [Closes #90]
"use Trait" can have comments [Closes #90]
"use Trait" can have comments [Closes #90]
"use Trait" can have comments [Closes #90]
"use Trait" can have comments [Closes #90]
"use Trait" can have comments [Closes #90]
"use Trait" can have comments [Closes #90]
"use Trait" can have comments [Closes #90]
"use Trait" can have comments [Closes #90]
"use Trait" can have comments [Closes #90]