@@ -183,7 +183,7 @@ public function setExtends($names): self
183
183
if (!is_string ($ names ) && !is_array ($ names )) {
184
184
throw new Nette \InvalidArgumentException ('Argument must be string or string[]. ' );
185
185
}
186
- $ this ->validate ((array ) $ names );
186
+ $ this ->validateNames ((array ) $ names );
187
187
$ this ->extends = $ names ;
188
188
return $ this ;
189
189
}
@@ -203,7 +203,7 @@ public function getExtends()
203
203
*/
204
204
public function addExtend (string $ name ): self
205
205
{
206
- $ this ->validate ([$ name ]);
206
+ $ this ->validateNames ([$ name ]);
207
207
$ this ->extends = (array ) $ this ->extends ;
208
208
$ this ->extends [] = $ name ;
209
209
return $ this ;
@@ -216,7 +216,7 @@ public function addExtend(string $name): self
216
216
*/
217
217
public function setImplements (array $ names ): self
218
218
{
219
- $ this ->validate ($ names );
219
+ $ this ->validateNames ($ names );
220
220
$ this ->implements = $ names ;
221
221
return $ this ;
222
222
}
@@ -236,7 +236,7 @@ public function getImplements(): array
236
236
*/
237
237
public function addImplement (string $ name ): self
238
238
{
239
- $ this ->validate ([$ name ]);
239
+ $ this ->validateNames ([$ name ]);
240
240
$ this ->implements [] = $ name ;
241
241
return $ this ;
242
242
}
@@ -248,7 +248,7 @@ public function addImplement(string $name): self
248
248
*/
249
249
public function setTraits (array $ names ): self
250
250
{
251
- $ this ->validate ($ names );
251
+ $ this ->validateNames ($ names );
252
252
$ this ->traits = array_fill_keys ($ names , []);
253
253
return $ this ;
254
254
}
@@ -277,7 +277,7 @@ public function getTraitResolutions(): array
277
277
*/
278
278
public function addTrait (string $ name , array $ resolutions = []): self
279
279
{
280
- $ this ->validate ([$ name ]);
280
+ $ this ->validateNames ([$ name ]);
281
281
$ this ->traits [$ name ] = $ resolutions ;
282
282
return $ this ;
283
283
}
@@ -461,7 +461,21 @@ public function removeMethod(string $name): self
461
461
}
462
462
463
463
464
- private function validate (array $ names ): void
464
+ /**
465
+ * @throws Nette\InvalidStateException
466
+ */
467
+ public function validate (): void
468
+ {
469
+ if ($ this ->abstract && $ this ->final ) {
470
+ throw new Nette \InvalidStateException ('Class cannot be abstract and final. ' );
471
+
472
+ } elseif (!$ this ->name && ($ this ->abstract || $ this ->final )) {
473
+ throw new Nette \InvalidStateException ('Anonymous class cannot be abstract or final. ' );
474
+ }
475
+ }
476
+
477
+
478
+ private function validateNames (array $ names ): void
465
479
{
466
480
foreach ($ names as $ name ) {
467
481
if (!Helpers::isNamespaceIdentifier ($ name , true )) {
0 commit comments