Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit d15b9c3

Browse files
committed
Requested changes
1 parent 1a93540 commit d15b9c3

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

src/Generator/PropertyGenerator.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,13 +226,20 @@ public function generate()
226226

227227
$output .= $this->indentation . $this->getVisibility() . ($this->isStatic() ? ' static' : '') . ' $' . $name;
228228

229-
if ($this->defaultValue instanceof PropertyValueGenerator &&
230-
$this->defaultValue->getType() === ValueGenerator::TYPE_OMIT) {
229+
if ($this->defaultValue instanceof PropertyValueGenerator && $this->defaultValue->omitValue()) {
231230
return $output . ';';
232231
}
233232

234-
$output .= ' = ' . ($defaultValue !== null ? $defaultValue->generate() : 'null;');
233+
return $output . ' = ' . ($defaultValue !== null ? $defaultValue->generate() : 'null;');
234+
}
235235

236-
return $output;
236+
/**
237+
* @return PropertyGenerator
238+
*/
239+
public function omitDefaultValue()
240+
{
241+
$this->defaultValue = new PropertyValueGenerator(null, PropertyValueGenerator::OMIT);
242+
243+
return $this;
237244
}
238245
}

src/Generator/ValueGenerator.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class ValueGenerator extends AbstractGenerator
3535
/**#@+
3636
* Constant values
3737
*/
38+
const OMIT = 'omit';
3839
const TYPE_AUTO = 'auto';
3940
const TYPE_BOOLEAN = 'boolean';
4041
const TYPE_BOOL = 'bool';
@@ -50,7 +51,6 @@ class ValueGenerator extends AbstractGenerator
5051
const TYPE_CONSTANT = 'constant';
5152
const TYPE_NULL = 'null';
5253
const TYPE_OBJECT = 'object';
53-
const TYPE_OMIT = 'omit';
5454
const TYPE_OTHER = 'other';
5555
/**#@-*/
5656

@@ -486,4 +486,12 @@ public function __toString()
486486
{
487487
return $this->generate();
488488
}
489+
490+
/**
491+
* @return bool
492+
*/
493+
public function omitValue()
494+
{
495+
return $this->type === self::OMIT;
496+
}
489497
}

test/Generator/PropertyGeneratorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ public function testSetDefaultValue(string $type, $value) : void
285285
public function testOmitType()
286286
{
287287
$property = new PropertyGenerator('test', null);
288-
$property->setDefaultValue(null, ValueGenerator::TYPE_OMIT);
288+
$property->omitDefaultValue();
289289

290290
self::assertEquals(' public $test;', $property->generate());
291291
}

0 commit comments

Comments
 (0)