diff --git a/doc/book/generator/reference.md b/doc/book/generator/reference.md index d811b950..c5a81718 100644 --- a/doc/book/generator/reference.md +++ b/doc/book/generator/reference.md @@ -358,6 +358,7 @@ class Zend\Code\Generator\ParameterGenerator extends Zend\Code\Generator\Abstrac public function getPassedByReference() public function setPassedByReference($passedByReference) public function generate() + public function omitDefaultValue() } ``` @@ -399,5 +400,6 @@ class Zend\Code\Generator\PropertyGenerator public function setDefaultValue($defaultValue) public function getDefaultValue() public function generate() + public function omitDefaultValue() } ``` diff --git a/src/Generator/ParameterGenerator.php b/src/Generator/ParameterGenerator.php index 0f3b2630..dc7c8d2f 100644 --- a/src/Generator/ParameterGenerator.php +++ b/src/Generator/ParameterGenerator.php @@ -90,14 +90,15 @@ public static function fromReflection(ParameterReflection $reflectionParameter) /** * Generate from array * - * @configkey name string [required] Class Name - * @configkey type string - * @configkey defaultvalue null|bool|string|int|float|array|ValueGenerator - * @configkey passedbyreference bool - * @configkey position int - * @configkey sourcedirty bool - * @configkey indentation string - * @configkey sourcecontent string + * @configkey name string [required] Class Name + * @configkey type string + * @configkey defaultvalue null|bool|string|int|float|array|ValueGenerator + * @configkey passedbyreference bool + * @configkey position int + * @configkey sourcedirty bool + * @configkey indentation string + * @configkey sourcecontent string + * @configkey omitdefaultvalue bool * * @throws Exception\InvalidArgumentException * @param array $array @@ -136,6 +137,9 @@ public static function fromArray(array $array) case 'sourcecontent': $param->setSourceContent($value); break; + case 'omitdefaultvalue': + $param->omitDefaultValue($value); + break; } } @@ -413,11 +417,12 @@ private function generateTypeHint() } /** + * @param bool $omit * @return ParameterGenerator */ - public function omitDefaultValue() + public function omitDefaultValue(bool $omit = true) { - $this->omitDefaultValue = true; + $this->omitDefaultValue = $omit; return $this; } diff --git a/src/Generator/PropertyGenerator.php b/src/Generator/PropertyGenerator.php index 8002634f..6259efc0 100644 --- a/src/Generator/PropertyGenerator.php +++ b/src/Generator/PropertyGenerator.php @@ -72,14 +72,15 @@ public static function fromReflection(PropertyReflection $reflectionProperty) /** * Generate from array * - * @configkey name string [required] Class Name - * @configkey const bool - * @configkey defaultvalue null|bool|string|int|float|array|ValueGenerator - * @configkey flags int - * @configkey abstract bool - * @configkey final bool - * @configkey static bool - * @configkey visibility string + * @configkey name string [required] Class Name + * @configkey const bool + * @configkey defaultvalue null|bool|string|int|float|array|ValueGenerator + * @configkey flags int + * @configkey abstract bool + * @configkey final bool + * @configkey static bool + * @configkey visibility string + * @configkey omitdefaultvalue bool * * @throws Exception\InvalidArgumentException * @param array $array @@ -122,6 +123,9 @@ public static function fromArray(array $array) case 'visibility': $property->setVisibility($value); break; + case 'omitdefaultvalue': + $property->omitDefaultValue($value); + break; } } @@ -239,11 +243,12 @@ public function generate() } /** + * @param bool $omit * @return PropertyGenerator */ - public function omitDefaultValue() + public function omitDefaultValue(bool $omit = true) { - $this->omitDefaultValue = true; + $this->omitDefaultValue = $omit; return $this; } diff --git a/test/Generator/ParameterGeneratorTest.php b/test/Generator/ParameterGeneratorTest.php index bd41bd4b..f1510b13 100644 --- a/test/Generator/ParameterGeneratorTest.php +++ b/test/Generator/ParameterGeneratorTest.php @@ -217,6 +217,7 @@ public function testCreateFromArray() 'sourcedirty' => false, 'sourcecontent' => 'foo', 'indentation' => '-', + 'omitdefaultvalue' => true, ]); self::assertEquals('SampleParameter', $parameterGenerator->getName()); @@ -227,6 +228,7 @@ public function testCreateFromArray() self::assertFalse($parameterGenerator->isSourceDirty()); self::assertEquals('foo', $parameterGenerator->getSourceContent()); self::assertEquals('-', $parameterGenerator->getIndentation()); + self::assertAttributeEquals(true, 'omitDefaultValue', $parameterGenerator); } /** diff --git a/test/Generator/PropertyGeneratorTest.php b/test/Generator/PropertyGeneratorTest.php index 1daa9555..077adb7b 100644 --- a/test/Generator/PropertyGeneratorTest.php +++ b/test/Generator/PropertyGeneratorTest.php @@ -223,16 +223,17 @@ public function testOtherTypesThrowExceptionOnGenerate() : void public function testCreateFromArray() : void { $propertyGenerator = PropertyGenerator::fromArray([ - 'name' => 'SampleProperty', - 'const' => true, - 'defaultvalue' => 'foo', - 'docblock' => [ + 'name' => 'SampleProperty', + 'const' => true, + 'defaultvalue' => 'foo', + 'docblock' => [ 'shortdescription' => 'foo', ], - 'abstract' => true, - 'final' => true, - 'static' => true, - 'visibility' => PropertyGenerator::VISIBILITY_PROTECTED, + 'abstract' => true, + 'final' => true, + 'static' => true, + 'visibility' => PropertyGenerator::VISIBILITY_PROTECTED, + 'omitdefaultvalue' => true, ]); self::assertEquals('SampleProperty', $propertyGenerator->getName()); @@ -243,6 +244,7 @@ public function testCreateFromArray() : void self::assertTrue($propertyGenerator->isFinal()); self::assertTrue($propertyGenerator->isStatic()); self::assertEquals(PropertyGenerator::VISIBILITY_PROTECTED, $propertyGenerator->getVisibility()); + self::assertAttributeEquals(true, 'omitDefaultValue', $propertyGenerator); } /**