|
30 | 30 | use Nette\PhpGenerator\Method;
|
31 | 31 | use Nette\PhpGenerator\PhpNamespace;
|
32 | 32 | use Nette\PhpGenerator\TraitType;
|
33 |
| -use RuntimeException; |
34 | 33 | use stdClass;
|
35 |
| -use Throwable; |
36 | 34 |
|
37 | 35 | use function array_key_last;
|
38 | 36 | use function array_map;
|
@@ -99,36 +97,26 @@ private function createFluentFactoryClass(GeneratorDefinition $definition): PhpN
|
99 | 97 | $staticFactory = ClassType::from(self::FACTORY_CLASS);
|
100 | 98 | assert($staticFactory instanceof ClassType);
|
101 | 99 | foreach ($staticFactory->getMethods() as $method) {
|
102 |
| - if (! $method->isPublic()) { |
103 |
| - continue; |
104 |
| - } |
105 |
| - |
106 |
| - try { |
107 |
| - $this->addMethod($method, $namespace, $class); |
108 |
| - } catch (Throwable $e) { |
109 |
| - throw new RuntimeException(sprintf('Failed to generate class for operator "%s"', $operator->name), 0, $e); |
110 |
| - } |
| 100 | + $this->addMethod($method, $class); |
111 | 101 | }
|
112 | 102 |
|
113 |
| - $staticFactory = TraitType::from(Stage\FactoryTrait::class); |
114 |
| - assert($staticFactory instanceof TraitType); |
115 |
| - foreach ($staticFactory->getMethods() as $method) { |
116 |
| - if (! $method->isPublic()) { |
117 |
| - continue; |
118 |
| - } |
119 |
| - |
120 |
| - try { |
121 |
| - $this->addMethod($method, $namespace, $class); |
122 |
| - } catch (Throwable $e) { |
123 |
| - throw new RuntimeException(sprintf('Failed to generate class for operator "%s"', $operator->name), 0, $e); |
| 103 | + foreach ($staticFactory->getTraits() as $trait) { |
| 104 | + $staticFactory = TraitType::from($trait->getName()); |
| 105 | + assert($staticFactory instanceof TraitType); |
| 106 | + foreach ($staticFactory->getMethods() as $method) { |
| 107 | + $this->addMethod($method, $class); |
124 | 108 | }
|
125 | 109 | }
|
126 | 110 |
|
127 | 111 | return $namespace;
|
128 | 112 | }
|
129 | 113 |
|
130 |
| - private function addMethod(Method $factoryMethod, PhpNamespace $namespace, ClassType $class): void |
| 114 | + private function addMethod(Method $factoryMethod, ClassType $class): void |
131 | 115 | {
|
| 116 | + if (! $factoryMethod->isPublic()) { |
| 117 | + return; |
| 118 | + } |
| 119 | + |
132 | 120 | if ($class->hasMethod($factoryMethod->getName())) {
|
133 | 121 | return;
|
134 | 122 | }
|
|
0 commit comments