1818use function is_scalar ;
1919use function is_string ;
2020use function ltrim ;
21+ use function method_exists ;
2122use function rtrim ;
2223use function sprintf ;
2324use function str_replace ;
@@ -117,10 +118,13 @@ public static function fromReflection(ClassReflection $classReflection)
117118
118119 $ constants = [];
119120
120- foreach ($ classReflection ->getConstants () as $ name => $ value ) {
121+ foreach ($ classReflection ->getReflectionConstants () as $ constReflection ) {
121122 $ constants [] = [
122- 'name ' => $ name ,
123- 'value ' => $ value ,
123+ 'name ' => $ constReflection ->getName (),
124+ 'value ' => $ constReflection ->getValue (),
125+ 'isFinal ' => method_exists ($ constReflection , 'isFinal ' )
126+ ? $ constReflection ->isFinal ()
127+ : false ,
124128 ];
125129 }
126130
@@ -159,7 +163,7 @@ public static function fromReflection(ClassReflection $classReflection)
159163 * @configkey methods
160164 * @throws Exception\InvalidArgumentException
161165 * @param array $array
162- * @return self
166+ * @return static
163167 */
164168 public static function fromArray (array $ array )
165169 {
@@ -255,7 +259,7 @@ public function __construct(
255259
256260 /**
257261 * @param string $name
258- * @return self
262+ * @return static
259263 */
260264 public function setName ($ name )
261265 {
@@ -279,7 +283,7 @@ public function getName()
279283
280284 /**
281285 * @param ?string $namespaceName
282- * @return self
286+ * @return static
283287 */
284288 public function setNamespaceName ($ namespaceName )
285289 {
@@ -296,7 +300,7 @@ public function getNamespaceName()
296300 }
297301
298302 /**
299- * @return self
303+ * @return static
300304 */
301305 public function setContainingFileGenerator (FileGenerator $ fileGenerator )
302306 {
@@ -313,7 +317,7 @@ public function getContainingFileGenerator()
313317 }
314318
315319 /**
316- * @return self
320+ * @return static
317321 */
318322 public function setDocBlock (DocBlockGenerator $ docBlock )
319323 {
@@ -331,7 +335,7 @@ public function getDocBlock()
331335
332336 /**
333337 * @param int[]|int $flags
334- * @return self
338+ * @return static
335339 */
336340 public function setFlags ($ flags )
337341 {
@@ -350,7 +354,7 @@ public function setFlags($flags)
350354
351355 /**
352356 * @param int $flag
353- * @return self
357+ * @return static
354358 */
355359 public function addFlag ($ flag )
356360 {
@@ -360,7 +364,7 @@ public function addFlag($flag)
360364
361365 /**
362366 * @param int $flag
363- * @return self
367+ * @return static
364368 */
365369 public function removeFlag ($ flag )
366370 {
@@ -370,7 +374,7 @@ public function removeFlag($flag)
370374
371375 /**
372376 * @param bool $isAbstract
373- * @return self
377+ * @return static
374378 */
375379 public function setAbstract ($ isAbstract )
376380 {
@@ -387,7 +391,7 @@ public function isAbstract()
387391
388392 /**
389393 * @param bool $isFinal
390- * @return self
394+ * @return static
391395 */
392396 public function setFinal ($ isFinal )
393397 {
@@ -405,7 +409,7 @@ public function isFinal()
405409 /**
406410 * @param ?string $extendedClass
407411 * @psalm-param ?class-string $extendedClass
408- * @return self
412+ * @return static
409413 */
410414 public function setExtendedClass ($ extendedClass )
411415 {
@@ -431,7 +435,7 @@ public function hasExtentedClass()
431435 }
432436
433437 /**
434- * @return self
438+ * @return static
435439 */
436440 public function removeExtentedClass ()
437441 {
@@ -442,7 +446,7 @@ public function removeExtentedClass()
442446 /**
443447 * @param string[] $implementedInterfaces
444448 * @psalm-param array<class-string> $implementedInterfaces
445- * @return self
449+ * @return static
446450 */
447451 public function setImplementedInterfaces (array $ implementedInterfaces )
448452 {
@@ -477,7 +481,7 @@ public function hasImplementedInterface($implementedInterface)
477481 /**
478482 * @param string $implementedInterface
479483 * @psalm-param class-string $implementedInterface
480- * @return self
484+ * @return static
481485 */
482486 public function removeImplementedInterface ($ implementedInterface )
483487 {
@@ -514,7 +518,7 @@ public function getConstants()
514518
515519 /**
516520 * @param string $constantName
517- * @return self
521+ * @return static
518522 */
519523 public function removeConstant ($ constantName )
520524 {
@@ -536,7 +540,7 @@ public function hasConstant($constantName)
536540 * Add constant from PropertyGenerator
537541 *
538542 * @throws Exception\InvalidArgumentException
539- * @return self
543+ * @return static
540544 */
541545 public function addConstantFromGenerator (PropertyGenerator $ constant )
542546 {
@@ -567,9 +571,9 @@ public function addConstantFromGenerator(PropertyGenerator $constant)
567571 * @param string $name Non-empty string
568572 * @param string|int|null|float|array $value Scalar
569573 * @throws Exception\InvalidArgumentException
570- * @return self
574+ * @return static
571575 */
572- public function addConstant ($ name , $ value )
576+ public function addConstant ($ name , $ value, bool $ isFinal = false )
573577 {
574578 if (empty ($ name ) || ! is_string ($ name )) {
575579 throw new Exception \InvalidArgumentException (sprintf (
@@ -581,13 +585,19 @@ public function addConstant($name, $value)
581585 $ this ->validateConstantValue ($ value );
582586
583587 return $ this ->addConstantFromGenerator (
584- new PropertyGenerator ($ name , new PropertyValueGenerator ($ value ), PropertyGenerator::FLAG_CONSTANT )
588+ new PropertyGenerator (
589+ $ name ,
590+ new PropertyValueGenerator ($ value ),
591+ $ isFinal
592+ ? PropertyGenerator::FLAG_CONSTANT | PropertyGenerator::FLAG_FINAL
593+ : PropertyGenerator::FLAG_CONSTANT
594+ )
585595 );
586596 }
587597
588598 /**
589599 * @param PropertyGenerator[]|array[] $constants
590- * @return self
600+ * @return static
591601 */
592602 public function addConstants (array $ constants )
593603 {
@@ -606,7 +616,7 @@ public function addConstants(array $constants)
606616
607617 /**
608618 * @param PropertyGenerator[]|string[]|array[] $properties
609- * @return self
619+ * @return static
610620 */
611621 public function addProperties (array $ properties )
612622 {
@@ -630,7 +640,7 @@ public function addProperties(array $properties)
630640 * @param string|array $defaultValue
631641 * @param int $flags
632642 * @throws Exception\InvalidArgumentException
633- * @return self
643+ * @return static
634644 */
635645 public function addProperty ($ name , $ defaultValue = null , $ flags = PropertyGenerator::FLAG_PUBLIC )
636646 {
@@ -655,7 +665,7 @@ public function addProperty($name, $defaultValue = null, $flags = PropertyGenera
655665 * Add property from PropertyGenerator
656666 *
657667 * @throws Exception\InvalidArgumentException
658- * @return self
668+ * @return static
659669 */
660670 public function addPropertyFromGenerator (PropertyGenerator $ property )
661671 {
@@ -706,7 +716,7 @@ public function getProperty($propertyName)
706716 *
707717 * @param string $use
708718 * @param string|null $useAlias
709- * @return self
719+ * @return static
710720 */
711721 public function addUse ($ use , $ useAlias = null )
712722 {
@@ -725,7 +735,7 @@ public function hasUse($use)
725735
726736 /**
727737 * @param string $use
728- * @return self
738+ * @return static
729739 */
730740 public function removeUse ($ use )
731741 {
@@ -744,7 +754,7 @@ public function hasUseAlias($use)
744754
745755 /**
746756 * @param string $use
747- * @return self
757+ * @return static
748758 */
749759 public function removeUseAlias ($ use )
750760 {
@@ -764,7 +774,7 @@ public function getUses()
764774
765775 /**
766776 * @param string $propertyName
767- * @return self
777+ * @return static
768778 */
769779 public function removeProperty ($ propertyName )
770780 {
@@ -784,7 +794,7 @@ public function hasProperty($propertyName)
784794
785795 /**
786796 * @param MethodGenerator[]|string[]|array[] $methods
787- * @return self
797+ * @return static
788798 */
789799 public function addMethods (array $ methods )
790800 {
@@ -810,7 +820,7 @@ public function addMethods(array $methods)
810820 * @param string $body
811821 * @param string $docBlock
812822 * @throws Exception\InvalidArgumentException
813- * @return self
823+ * @return static
814824 */
815825 public function addMethod (
816826 $ name ,
@@ -834,7 +844,7 @@ public function addMethod(
834844 * Add Method from MethodGenerator
835845 *
836846 * @throws Exception\InvalidArgumentException
837- * @return self
847+ * @return static
838848 */
839849 public function addMethodFromGenerator (MethodGenerator $ method )
840850 {
@@ -870,7 +880,7 @@ public function getMethod($methodName)
870880
871881 /**
872882 * @param string $methodName
873- * @return self
883+ * @return static
874884 */
875885 public function removeMethod ($ methodName )
876886 {
0 commit comments