From fa4340ca7455dd11837e791c492607a471478790 Mon Sep 17 00:00:00 2001 From: Theodore Brown Date: Fri, 29 Nov 2024 14:08:38 -0600 Subject: [PATCH] Remove unnecessary getDefaultValues method Defaults can be set via processValues instead. --- src/Entities.php | 11 ----------- test/src/Users.php | 10 ++++++---- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/src/Entities.php b/src/Entities.php index 323ac68..afa0075 100644 --- a/src/Entities.php +++ b/src/Entities.php @@ -117,15 +117,6 @@ protected function getSelectProps(): array return []; } - /** - * Allows default values to be specified for mapped properties. - * These defaults are only used when adding entities. - */ - protected function getDefaultValues(): array - { - return []; - } - /** * Can modify the filter or throw an exception if it is invalid * @param mixed[] $filter @@ -207,13 +198,11 @@ public function addEntities(array $entities): array return []; } - $defaultValues = $this->getDefaultValues(); $rows = []; $existingIds = []; foreach ($entities as $key => $entity) { unset($entity[$this->idField]); // any ID posted to API should be ignored - $entity = array_replace_recursive($defaultValues, $entity); $entity = $this->processValues($entity, []); // if processValues sets an ID for an existing item, don't insert a new row for it diff --git a/test/src/Users.php b/test/src/Users.php index 60cdb0f..caf13f5 100644 --- a/test/src/Users.php +++ b/test/src/Users.php @@ -25,10 +25,12 @@ protected function getSelectProps(): array ]; } - protected function getDefaultValues(): array + protected function processValues(array $data, array $ids): array { - return [ - 'isDisabled' => false, - ]; + if (!$ids && !isset($data['isDisabled'])) { + $data['isDisabled'] = false; + } + + return $data; } }