-
Notifications
You must be signed in to change notification settings - Fork 79
Add omit property value type #131
Add omit property value type #131
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@janvernieuwe since this is an improvement, could you please target develop
?
src/Generator/PropertyGenerator.php
Outdated
return $output . ';'; | ||
} | ||
|
||
$output .= ' = ' . ($defaultValue !== null ? $defaultValue->generate() : 'null;'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can return directly here
src/Generator/ValueGenerator.php
Outdated
@@ -50,6 +50,7 @@ class ValueGenerator extends AbstractGenerator | |||
const TYPE_CONSTANT = 'constant'; | |||
const TYPE_NULL = 'null'; | |||
const TYPE_OBJECT = 'object'; | |||
const TYPE_OMIT = 'omit'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
omit
is not really a type
src/Generator/PropertyGenerator.php
Outdated
$output .= $this->indentation . $this->getVisibility() . ($this->isStatic() ? ' static' : '') . ' $' . $name; | ||
|
||
if ($this->defaultValue instanceof PropertyValueGenerator && | ||
$this->defaultValue->getType() === ValueGenerator::TYPE_OMIT) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$this->defaultValue->omitType()
instead - that gets rid of the ugly constant too ;-)
public function testOmitType() | ||
{ | ||
$property = new PropertyGenerator('test', null); | ||
$property->setDefaultValue(null, ValueGenerator::TYPE_OMIT); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's really really ugly. Would rather prefer ->removeDefaultValue()
or ->omitDefaultValue()
instead of having a ValueGenerator
with special purposes (there is a big impedance between the concept of a value generator and the concept of a lack of value)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll remove the constant, and move it to a property in the PropertyGenerator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you look at the other comments, I suggest not touching the PropertyGenerator
at all
I'm not too sure about how omitDefaultValue is better implemented, see the last commit. |
@janvernieuwe the idea is to have the |
use a property instead of constant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🚢
Thanks @janvernieuwe \o/ |
Fixes #28