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

Commit e19867a

Browse files
committed
Add omitValue
use a property instead of constant
1 parent 28f8186 commit e19867a

File tree

5 files changed

+38
-13
lines changed

5 files changed

+38
-13
lines changed

src/Generator/ParameterGenerator.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ class ParameterGenerator extends AbstractGenerator
4949
*/
5050
private $variadic = false;
5151

52+
/**
53+
* @var bool
54+
*/
55+
private $omitDefaultValue = false;
56+
5257
/**
5358
* @param ParameterReflection $reflectionParameter
5459
* @return ParameterGenerator
@@ -306,6 +311,10 @@ public function generate()
306311

307312
$output .= '$' . $this->name;
308313

314+
if ($this->omitDefaultValue) {
315+
return $output;
316+
}
317+
309318
if ($this->defaultValue !== null) {
310319
$output .= ' = ';
311320
if (is_string($this->defaultValue)) {
@@ -402,4 +411,14 @@ private function generateTypeHint()
402411

403412
return $this->type->generate() . ' ';
404413
}
414+
415+
/**
416+
* @return ParameterGenerator
417+
*/
418+
public function omitDefaultValue()
419+
{
420+
$this->omitDefaultValue = true;
421+
422+
return $this;
423+
}
405424
}

src/Generator/PropertyGenerator.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ class PropertyGenerator extends AbstractMemberGenerator
2929
*/
3030
protected $defaultValue;
3131

32+
/**
33+
* @var bool
34+
*/
35+
private $omitDefaultValue = false;
36+
3237
/**
3338
* @param PropertyReflection $reflectionProperty
3439
* @return PropertyGenerator
@@ -226,7 +231,7 @@ public function generate()
226231

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

229-
if ($this->defaultValue instanceof PropertyValueGenerator && $this->defaultValue->omitValue()) {
234+
if ($this->omitDefaultValue) {
230235
return $output . ';';
231236
}
232237

@@ -238,6 +243,8 @@ public function generate()
238243
*/
239244
public function omitDefaultValue()
240245
{
241-
return $this->setDefaultValue(null, PropertyValueGenerator::OMIT);
246+
$this->omitDefaultValue = true;
247+
248+
return $this;
242249
}
243250
}

src/Generator/ValueGenerator.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ class ValueGenerator extends AbstractGenerator
3535
/**#@+
3636
* Constant values
3737
*/
38-
const OMIT = 'omit';
3938
const TYPE_AUTO = 'auto';
4039
const TYPE_BOOLEAN = 'boolean';
4140
const TYPE_BOOL = 'bool';
@@ -486,12 +485,4 @@ public function __toString()
486485
{
487486
return $this->generate();
488487
}
489-
490-
/**
491-
* @return bool
492-
*/
493-
public function omitValue()
494-
{
495-
return $this->type === self::OMIT;
496-
}
497488
}

test/Generator/ParameterGeneratorTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,4 +582,12 @@ public function testGetInternalClassDefaultParameterValue()
582582

583583
self::assertSame('null', strtolower((string) $parameter->getDefaultValue()));
584584
}
585+
586+
public function testOmitType()
587+
{
588+
$parameter = new ParameterGenerator('foo', 'string', 'bar');
589+
$parameter->omitDefaultValue();
590+
591+
self::assertEquals('string $foo', $parameter->generate());
592+
}
585593
}

test/Generator/PropertyGeneratorTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,9 @@ public function testSetDefaultValue(string $type, $value) : void
284284

285285
public function testOmitType()
286286
{
287-
$property = new PropertyGenerator('test', null);
287+
$property = new PropertyGenerator('foo', null);
288288
$property->omitDefaultValue();
289289

290-
self::assertEquals(' public $test;', $property->generate());
290+
self::assertEquals(' public $foo;', $property->generate());
291291
}
292292
}

0 commit comments

Comments
 (0)