Skip to content

Commit

Permalink
Use proper 'get' method when calling method within the toArray method.
Browse files Browse the repository at this point in the history
  • Loading branch information
thefrosty committed Oct 28, 2019
1 parent 1dd7cd9 commit c793db8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -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": [
{
Expand Down
6 changes: 5 additions & 1 deletion src/Models/BaseModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit c793db8

Please sign in to comment.