@@ -7,30 +7,30 @@ |
||
| 7 | 7 | |
| 8 | 8 | class FactoryMuffin extends OriginalFactoryMuffin |
| 9 | 9 | { |
| 10 | - /** |
|
| 11 | - * Generate and set the model attributes. |
|
| 12 | - * NOTE: Patch the original method to support dynamic setter and getter |
|
| 13 | - * of the OCP\AppFramework\Db\Entity class |
|
| 14 | - * |
|
| 15 | - * @param object $model The model instance. |
|
| 16 | - * @param array $attr The model attributes. |
|
| 17 | - * |
|
| 18 | - * @return void |
|
| 19 | - */ |
|
| 20 | - protected function generate($model, array $attr = []) |
|
| 21 | - { |
|
| 22 | - foreach ($attr as $key => $kind) { |
|
| 23 | - $value = $this->factory->generate($kind, $model, $this); |
|
| 10 | + /** |
|
| 11 | + * Generate and set the model attributes. |
|
| 12 | + * NOTE: Patch the original method to support dynamic setter and getter |
|
| 13 | + * of the OCP\AppFramework\Db\Entity class |
|
| 14 | + * |
|
| 15 | + * @param object $model The model instance. |
|
| 16 | + * @param array $attr The model attributes. |
|
| 17 | + * |
|
| 18 | + * @return void |
|
| 19 | + */ |
|
| 20 | + protected function generate($model, array $attr = []) |
|
| 21 | + { |
|
| 22 | + foreach ($attr as $key => $kind) { |
|
| 23 | + $value = $this->factory->generate($kind, $model, $this); |
|
| 24 | 24 | |
| 25 | - $setter = 'set'.ucfirst(static::camelize($key)); |
|
| 26 | - // check if there is a setter and use it instead |
|
| 27 | - if ($model instanceof Entity && is_callable([$model, $setter])) { |
|
| 28 | - $model->$setter($value); |
|
| 29 | - } elseif (method_exists($model, $setter) && is_callable([$model, $setter])) { |
|
| 30 | - $model->$setter($value); |
|
| 31 | - } else { |
|
| 32 | - $model->$key = $value; |
|
| 33 | - } |
|
| 34 | - } |
|
| 35 | - } |
|
| 25 | + $setter = 'set'.ucfirst(static::camelize($key)); |
|
| 26 | + // check if there is a setter and use it instead |
|
| 27 | + if ($model instanceof Entity && is_callable([$model, $setter])) { |
|
| 28 | + $model->$setter($value); |
|
| 29 | + } elseif (method_exists($model, $setter) && is_callable([$model, $setter])) { |
|
| 30 | + $model->$setter($value); |
|
| 31 | + } else { |
|
| 32 | + $model->$key = $value; |
|
| 33 | + } |
|
| 34 | + } |
|
| 35 | + } |
|
| 36 | 36 | } |
@@ -22,7 +22,7 @@ |
||
| 22 | 22 | foreach ($attr as $key => $kind) { |
| 23 | 23 | $value = $this->factory->generate($kind, $model, $this); |
| 24 | 24 | |
| 25 | - $setter = 'set'.ucfirst(static::camelize($key)); |
|
| 25 | + $setter = 'set' . ucfirst(static::camelize($key)); |
|
| 26 | 26 | // check if there is a setter and use it instead |
| 27 | 27 | if ($model instanceof Entity && is_callable([$model, $setter])) { |
| 28 | 28 | $model->$setter($value); |
@@ -5,8 +5,7 @@ discard block |
||
| 5 | 5 | use League\FactoryMuffin\FactoryMuffin as OriginalFactoryMuffin; |
| 6 | 6 | use OCP\AppFramework\Db\Entity; |
| 7 | 7 | |
| 8 | -class FactoryMuffin extends OriginalFactoryMuffin |
|
| 9 | -{ |
|
| 8 | +class FactoryMuffin extends OriginalFactoryMuffin { |
|
| 10 | 9 | /** |
| 11 | 10 | * Generate and set the model attributes. |
| 12 | 11 | * NOTE: Patch the original method to support dynamic setter and getter |
@@ -17,8 +16,7 @@ discard block |
||
| 17 | 16 | * |
| 18 | 17 | * @return void |
| 19 | 18 | */ |
| 20 | - protected function generate($model, array $attr = []) |
|
| 21 | - { |
|
| 19 | + protected function generate($model, array $attr = []) { |
|
| 22 | 20 | foreach ($attr as $key => $kind) { |
| 23 | 21 | $value = $this->factory->generate($kind, $model, $this); |
| 24 | 22 | |