From f19385ccc19b81c1d171a755622b16b1c3f2d3e3 Mon Sep 17 00:00:00 2001 From: Aldarien Date: Mon, 12 Sep 2022 17:33:45 -0300 Subject: [PATCH] FIX: use getMethod instead of string --- src/Alias/Model/Repository.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Alias/Model/Repository.php b/src/Alias/Model/Repository.php index d5a521e..1e75b02 100644 --- a/src/Alias/Model/Repository.php +++ b/src/Alias/Model/Repository.php @@ -150,25 +150,26 @@ abstract class Repository implements RepositoryInterface public function fillData(Model $model, array $data): Model { foreach ($this->getRequired() as $column) { - $m = 'set' . ucwords($column); + $m = $this->getMethod($column, false); $model->{$m}($data[$column]); } foreach ($this->getOptional() as $column) { - if (isset($data[$column])) { - $m = 'set' . ucwords($column); - $model->{$m}($data[$column]); + if (!isset($data[$column])) { + continue; } + $m = $this->getMethod($column, false); + $model->{$m}($data[$column]); } return $model; } public function mapArray(Model $model, array $data): array { foreach ($this->getColumns() as $column) { - $m = $this->getMethod($column); - $val = $model->{$m}(); if (isset($data[$column])) { continue; } + $m = $this->getMethod($column); + $val = $model->{$m}(); $data[$column] = $val; } return $data; @@ -215,7 +216,7 @@ abstract class Repository implements RepositoryInterface { foreach ($this->getColumns() as $col) { if (isset($data[$col])) { - $m = 'set' . ucwords($col); + $m = $this->getMethod($col, false); $model->{$m}($data[$col]); } }