Open thekid opened 9 years ago
The README file should contain how to extend this library with custom transformations:
<?php namespace com\example\transform; /** * Creates `getX()` and `setX()` accessors for all member variables. */ class MutableValueObject extends \lang\kind\Transformation { /** * Creates trait body * * @param lang.mirrors.TypeMirror $mirror * @return string */ protected function body($mirror) { $body= ''; foreach ($this->instanceFields($mirror) as $field) { $name= $field->name(); $body.= 'public function get'.ucfirst($name).'() { return $this->'.$name.'; }'; $body.= 'public function set'.ucfirst($name).'($arg) { $this->'.$name.'= $arg; }'; } return $body; } }
Maybe think of a declaration helper:
$body.= $this->declare('get'.ucfirst($name), [], '{ return $this->name; }'); $body.= $this->declare('set'.ucfirst($name), ['arg' => $field->type()], '{ $this->name= $arg; }');
The README file should contain how to extend this library with custom transformations: