PhpNamespace classes can't be added to a PhpFile class.
Example
<?php declare(strict_types=1);
use Nette\PhpGenerator\ClassType;
use Nette\PhpGenerator\PhpFile;
use Nette\PhpGenerator\PhpNamespace;
$phpFile= new PhpFile();
$namespace = new PhpNamespace('FooBar');
$class = new ClassType('Foo');
$method = $class->addMethod('baz');
$method->setReturnType('FooBar\\Bar');
$method->setBody('return new Bar();');
$namespace->add($class);
$namespace->add(new ClassType('Bar'));
$phpFile->add($namespace);
echo $phpFile;
Expected result:
<?php
namespace FooBar;
class Foo
{
public function baz(): Bar
{
return new Bar();
}
}
class Bar
{
}
Description
PhpNamespace
classes can't be added to aPhpFile
class.Example
Expected result: