From c793db8d34d6315f0b35afc539f2d25eab1ffd19 Mon Sep 17 00:00:00 2001 From: Austin Passy <367897+thefrosty@users.noreply.github.com> Date: Mon, 28 Oct 2019 12:37:25 -0700 Subject: [PATCH] Use proper 'get' method when calling method within the toArray method. --- CHANGELOG.md | 4 ++++ composer.json | 2 +- src/Models/BaseModel.php | 6 +++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index adb7a2a..02d781c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## Unreleased PHP version >= 7.2 & WordPress version >= 5.1 will be required by version `2.0`. +## [1.6.2] - 2019-10-28 +### Updated +- In the `BaseModel` class update the get method call to use the `getMethod` helper in `toArray`. + ## [1.6.1] - 2019-10-02 ### Added - Added `getCustomDelimiters` method to the BaseModel to allow additional search/delimiters to be added to the getMethod diff --git a/composer.json b/composer.json index b5ad2ee..7a18d8e 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "thefrosty/wp-utilities", "description": "A library containing my standard development resources", - "version": "1.6.1", + "version": "1.6.2", "license": "MIT", "authors": [ { diff --git a/src/Models/BaseModel.php b/src/Models/BaseModel.php index 7ba521e..4c615a7 100644 --- a/src/Models/BaseModel.php +++ b/src/Models/BaseModel.php @@ -46,7 +46,11 @@ public function toArray() : array $result = []; foreach ($this->getSerializableFields() as $index => $field_name) { - $value = $this->{'get' . \ucwords($field_name)}(); + $method = $this->getMethod('get', $field_name); + if (!\method_exists($this, $method)) { + continue; + } + $value = $this->$method(); if (\is_object($value) && \method_exists($value, 'toArray')) { $result[$field_name] = $value->toArray(); continue;