Skip to content

Commit

Permalink
allow setting getters/setters body (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
dakorpar authored Mar 6, 2019
1 parent 711647a commit 87cb1dc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
10 changes: 10 additions & 0 deletions src/Generator/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,21 @@ public function __construct(?array $config = null)
*/
public $getterVisibility = 'public';

/**
* @var string
*/
public $getterBody = 'return $this->__FIELD__;';

/**
* @var string
*/
public $setterVisibility = 'public';

/**
* @var string
*/
public $setterBody = '$this[\'__FIELD__\'] = $value;' . "\n" . 'return $this;';

/**
* @var bool
*/
Expand Down
5 changes: 2 additions & 3 deletions src/Generator/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ protected function generateColumn(ClassType $entity, Column $column): void
if ($this->config->generateGetters) {
$getter = $entity->addMethod('get' . Inflector::classify($column->getField()));
$getter->setVisibility($this->config->getterVisibility)
->addBody('return $this->' . $column->getField() . ';')
->addBody(str_replace('__FIELD__', $column->getField(), $this->config->getterBody))
->setReturnType($type)
->setReturnNullable($column->isNullable());
}
Expand All @@ -139,8 +139,7 @@ protected function generateColumn(ClassType $entity, Column $column): void
$setter = $entity->addMethod('set' . Inflector::classify($column->getField()));
$setter->setVisibility($this->config->setterVisibility);
$setter->addParameter('value')->setTypeHint($type)->setNullable($column->isNullable());
$setter->addBody('$this[\'' . $column->getField() . '\'] = $value;');
$setter->addBody('return $this;');
$setter->addBody(str_replace('__FIELD__', $column->getField(), $this->config->setterBody));
$setter->setReturnType('self');
}
}
Expand Down

0 comments on commit 87cb1dc

Please sign in to comment.