@@ -78,7 +78,7 @@ class ClassGenerator extends AbstractGenerator
78
78
* Build a Code Generation Php Object from a Class Reflection
79
79
*
80
80
* @param ClassReflection $classReflection
81
- * @return ClassGenerator
81
+ * @return self
82
82
*/
83
83
public static function fromReflection (ClassReflection $ classReflection )
84
84
{
@@ -167,7 +167,7 @@ public static function fromReflection(ClassReflection $classReflection)
167
167
*
168
168
* @throws Exception\InvalidArgumentException
169
169
* @param array $array
170
- * @return ClassGenerator
170
+ * @return self
171
171
*/
172
172
public static function fromArray (array $ array )
173
173
{
@@ -262,7 +262,7 @@ public function __construct(
262
262
263
263
/**
264
264
* @param string $name
265
- * @return ClassGenerator
265
+ * @return self
266
266
*/
267
267
public function setName ($ name )
268
268
{
@@ -286,7 +286,7 @@ public function getName()
286
286
287
287
/**
288
288
* @param string $namespaceName
289
- * @return ClassGenerator
289
+ * @return self
290
290
*/
291
291
public function setNamespaceName ($ namespaceName )
292
292
{
@@ -304,7 +304,7 @@ public function getNamespaceName()
304
304
305
305
/**
306
306
* @param FileGenerator $fileGenerator
307
- * @return ClassGenerator
307
+ * @return self
308
308
*/
309
309
public function setContainingFileGenerator (FileGenerator $ fileGenerator )
310
310
{
@@ -322,7 +322,7 @@ public function getContainingFileGenerator()
322
322
323
323
/**
324
324
* @param DocBlockGenerator $docBlock
325
- * @return ClassGenerator
325
+ * @return self
326
326
*/
327
327
public function setDocBlock (DocBlockGenerator $ docBlock )
328
328
{
@@ -340,7 +340,7 @@ public function getDocBlock()
340
340
341
341
/**
342
342
* @param array|string $flags
343
- * @return ClassGenerator
343
+ * @return self
344
344
*/
345
345
public function setFlags ($ flags )
346
346
{
@@ -359,7 +359,7 @@ public function setFlags($flags)
359
359
360
360
/**
361
361
* @param string $flag
362
- * @return ClassGenerator
362
+ * @return self
363
363
*/
364
364
public function addFlag ($ flag )
365
365
{
@@ -369,7 +369,7 @@ public function addFlag($flag)
369
369
370
370
/**
371
371
* @param string $flag
372
- * @return ClassGenerator
372
+ * @return self
373
373
*/
374
374
public function removeFlag ($ flag )
375
375
{
@@ -379,7 +379,7 @@ public function removeFlag($flag)
379
379
380
380
/**
381
381
* @param bool $isAbstract
382
- * @return ClassGenerator
382
+ * @return self
383
383
*/
384
384
public function setAbstract ($ isAbstract )
385
385
{
@@ -396,7 +396,7 @@ public function isAbstract()
396
396
397
397
/**
398
398
* @param bool $isFinal
399
- * @return ClassGenerator
399
+ * @return self
400
400
*/
401
401
public function setFinal ($ isFinal )
402
402
{
@@ -413,7 +413,7 @@ public function isFinal()
413
413
414
414
/**
415
415
* @param string $extendedClass
416
- * @return ClassGenerator
416
+ * @return self
417
417
*/
418
418
public function setExtendedClass ($ extendedClass )
419
419
{
@@ -429,12 +429,33 @@ public function getExtendedClass()
429
429
return $ this ->extendedClass ;
430
430
}
431
431
432
+ /**
433
+ * @return bool
434
+ */
435
+ public function hasExtentedClass ()
436
+ {
437
+ return !empty ($ this ->extendedClass );
438
+ }
439
+
440
+ /**
441
+ * @return self
442
+ */
443
+ public function removeExtentedClass ()
444
+ {
445
+ $ this ->setExtendedClass (null );
446
+ return $ this ;
447
+ }
448
+
432
449
/**
433
450
* @param array $implementedInterfaces
434
- * @return ClassGenerator
451
+ * @return self
435
452
*/
436
453
public function setImplementedInterfaces (array $ implementedInterfaces )
437
454
{
455
+ array_map (function ($ implementedInterface ) {
456
+ return (string ) TypeGenerator::fromTypeString ($ implementedInterface );
457
+ }, $ implementedInterfaces );
458
+
438
459
$ this ->implementedInterfaces = $ implementedInterfaces ;
439
460
return $ this ;
440
461
}
@@ -447,9 +468,29 @@ public function getImplementedInterfaces()
447
468
return $ this ->implementedInterfaces ;
448
469
}
449
470
471
+ /**
472
+ * @param string $implementedInterface
473
+ * @return bool
474
+ */
475
+ public function hasImplementedInterface ($ implementedInterface )
476
+ {
477
+ $ implementedInterface = (string ) TypeGenerator::fromTypeString ($ implementedInterface );
478
+ return in_array ($ implementedInterface , $ this ->implementedInterfaces );
479
+ }
480
+
481
+ /**
482
+ * @param $implementedInterface
483
+ * @return self
484
+ */
485
+ public function removeImplementedInterface ($ implementedInterface )
486
+ {
487
+ $ implementedInterface = (string ) TypeGenerator::fromTypeString ($ implementedInterface );
488
+ unset($ this ->implementedInterfaces [array_search ($ implementedInterface , $ this ->implementedInterfaces )]);
489
+ return $ this ;
490
+ }
491
+
450
492
/**
451
493
* @param string $constantName
452
- *
453
494
* @return PropertyGenerator|false
454
495
*/
455
496
public function getConstant ($ constantName )
@@ -469,6 +510,17 @@ public function getConstants()
469
510
return $ this ->constants ;
470
511
}
471
512
513
+ /**
514
+ * @param string $constantName
515
+ * @return self
516
+ */
517
+ public function removeConstant ($ constantName )
518
+ {
519
+ unset($ this ->constants [$ constantName ]);
520
+
521
+ return $ this ;
522
+ }
523
+
472
524
/**
473
525
* @param string $constantName
474
526
* @return bool
@@ -483,7 +535,7 @@ public function hasConstant($constantName)
483
535
*
484
536
* @param PropertyGenerator $constant
485
537
* @throws Exception\InvalidArgumentException
486
- * @return ClassGenerator
538
+ * @return self
487
539
*/
488
540
public function addConstantFromGenerator (PropertyGenerator $ constant )
489
541
{
@@ -516,7 +568,7 @@ public function addConstantFromGenerator(PropertyGenerator $constant)
516
568
*
517
569
* @throws Exception\InvalidArgumentException
518
570
*
519
- * @return ClassGenerator
571
+ * @return self
520
572
*/
521
573
public function addConstant ($ name , $ value )
522
574
{
@@ -537,7 +589,7 @@ public function addConstant($name, $value)
537
589
/**
538
590
* @param PropertyGenerator[]|array[] $constants
539
591
*
540
- * @return ClassGenerator
592
+ * @return self
541
593
*/
542
594
public function addConstants (array $ constants )
543
595
{
@@ -556,7 +608,7 @@ public function addConstants(array $constants)
556
608
557
609
/**
558
610
* @param array $properties
559
- * @return ClassGenerator
611
+ * @return self
560
612
*/
561
613
public function addProperties (array $ properties )
562
614
{
@@ -582,7 +634,7 @@ public function addProperties(array $properties)
582
634
* @param string|array $defaultValue
583
635
* @param int $flags
584
636
* @throws Exception\InvalidArgumentException
585
- * @return ClassGenerator
637
+ * @return self
586
638
*/
587
639
public function addProperty ($ name , $ defaultValue = null , $ flags = PropertyGenerator::FLAG_PUBLIC )
588
640
{
@@ -608,7 +660,7 @@ public function addProperty($name, $defaultValue = null, $flags = PropertyGenera
608
660
*
609
661
* @param PropertyGenerator $property
610
662
* @throws Exception\InvalidArgumentException
611
- * @return ClassGenerator
663
+ * @return self
612
664
*/
613
665
public function addPropertyFromGenerator (PropertyGenerator $ property )
614
666
{
@@ -659,14 +711,52 @@ public function getProperty($propertyName)
659
711
*
660
712
* @param string $use
661
713
* @param string|null $useAlias
662
- * @return ClassGenerator
714
+ * @return self
663
715
*/
664
716
public function addUse ($ use , $ useAlias = null )
665
717
{
666
718
$ this ->traitUsageGenerator ->addUse ($ use , $ useAlias );
667
719
return $ this ;
668
720
}
669
721
722
+ /**
723
+ * @param string $use
724
+ * @return self
725
+ */
726
+ public function hasUse ($ use )
727
+ {
728
+ return $ this ->traitUsageGenerator ->hasUse ($ use );
729
+ }
730
+
731
+ /**
732
+ * @param string $use
733
+ * @return self
734
+ */
735
+ public function removeUse ($ use )
736
+ {
737
+ $ this ->traitUsageGenerator ->removeUse ($ use );
738
+ return $ this ;
739
+ }
740
+
741
+ /**
742
+ * @param string $use
743
+ * @return bool
744
+ */
745
+ public function hasUseAlias ($ use )
746
+ {
747
+ return $ this ->traitUsageGenerator ->hasUseAlias ($ use );
748
+ }
749
+
750
+ /**
751
+ * @param $use
752
+ * @return self
753
+ */
754
+ public function removeUseAlias ($ use )
755
+ {
756
+ $ this ->traitUsageGenerator ->removeUseAlias ($ use );
757
+ return $ this ;
758
+ }
759
+
670
760
/**
671
761
* Returns the "use" classes
672
762
*
@@ -677,6 +767,18 @@ public function getUses()
677
767
return $ this ->traitUsageGenerator ->getUses ();
678
768
}
679
769
770
+
771
+ /**
772
+ * @param string $propertyName
773
+ * @return self
774
+ */
775
+ public function removeProperty ($ propertyName )
776
+ {
777
+ unset($ this ->properties [$ propertyName ]);
778
+
779
+ return $ this ;
780
+ }
781
+
680
782
/**
681
783
* @param string $propertyName
682
784
* @return bool
@@ -688,7 +790,7 @@ public function hasProperty($propertyName)
688
790
689
791
/**
690
792
* @param array $methods
691
- * @return ClassGenerator
793
+ * @return self
692
794
*/
693
795
public function addMethods (array $ methods )
694
796
{
@@ -716,7 +818,7 @@ public function addMethods(array $methods)
716
818
* @param string $body
717
819
* @param string $docBlock
718
820
* @throws Exception\InvalidArgumentException
719
- * @return ClassGenerator
821
+ * @return self
720
822
*/
721
823
public function addMethod (
722
824
$ name ,
@@ -741,7 +843,7 @@ public function addMethod(
741
843
*
742
844
* @param MethodGenerator $method
743
845
* @throws Exception\InvalidArgumentException
744
- * @return ClassGenerator
846
+ * @return self
745
847
*/
746
848
public function addMethodFromGenerator (MethodGenerator $ method )
747
849
{
@@ -777,13 +879,11 @@ public function getMethod($methodName)
777
879
778
880
/**
779
881
* @param string $methodName
780
- * @return ClassGenerator
882
+ * @return self
781
883
*/
782
884
public function removeMethod ($ methodName )
783
885
{
784
- if ($ this ->hasMethod ($ methodName )) {
785
- unset($ this ->methods [strtolower ($ methodName )]);
786
- }
886
+ unset($ this ->methods [strtolower ($ methodName )]);
787
887
788
888
return $ this ;
789
889
}
0 commit comments