Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.0.x] - Renamed the arrayToObject to toObject #14389

Merged
merged 4 commits into from
Sep 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG-4.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
- Changed `Phalcon\Mvc\Router\Annotations` to be able to handle patterns az prefixes [#14259](https://github.com/phalcon/cphalcon/pull/14259)
- Changed `Phalcon\Mvc\Router\Group::routes` to an array as default [#14259](https://github.com/phalcon/cphalcon/pull/14259)
- Changed `Phalcon\Mvc\Model::assign` changed order of parameters to $data, $whiteList, $dataColumnMap [#14386](https://github.com/phalcon/cphalcon/pull/14386)

- Changed `Phalcon\Helper\Arr::arrayToObject` to `toObject` [#14389](https://github.com/phalcon/cphalcon/pull/14389)

## Fixed
- Fixed `Phalcon\Helper\Str::includes` to return correct result [#14301](https://github.com/phalcon/cphalcon/issues/14301)
Expand Down
21 changes: 8 additions & 13 deletions phalcon/Helper/Arr.zep
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,6 @@ use stdClass;
*/
class Arr
{
final public static function arrayToObject(array! collection)
{
var returnObject, key, value;

let returnObject = new stdClass();

for key, value in collection {
let returnObject->{key} = value;
}

return returnObject;
}

/**
* Chunks an array into smaller arrays of a specified size.
*
Expand Down Expand Up @@ -350,6 +337,14 @@ class Arr
];
}

/**
* Returns the passed array as an object
*/
final public static function toObject(array! collection)
{
return (object) collection;
}

/**
* Returns true if the provided function returns true for all elements of
* the collection, false otherwise.
Expand Down
2 changes: 1 addition & 1 deletion phalcon/Mvc/Model.zep
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,7 @@ abstract class Model extends AbstractInjectionAware implements EntityInterface,
}

if hydrationMode != Resultset::HYDRATE_ARRAYS {
return Arr::arrayToObject(hydrateArray);
return Arr::toObject(hydrateArray);
}

return hydrateArray;
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/Helper/Arr/PluckCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public function helperArrPluckObject(UnitTester $I)
{
$I->wantToTest('Helper\Arr - pluck()');
$collection = [
Arr::arrayToObject(['product_id' => 'prod-100', 'name' => 'Desk']),
Arr::arrayToObject(['product_id' => 'prod-200', 'name' => 'Chair']),
Arr::toObject(['product_id' => 'prod-100', 'name' => 'Desk']),
Arr::toObject(['product_id' => 'prod-200', 'name' => 'Chair']),
];

$expected = ['Desk', 'Chair'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,24 @@
use stdClass;
use UnitTester;

class ArrayToObjectCest
class ToObjectCest
{
/**
* Unit Tests Phalcon\Helper\Arr :: arrayToObject()
* Unit Tests Phalcon\Helper\Arr :: toObject()
*
* @author Phalcon Team <[email protected]>
* @since 2019-05-25
*/
public function helperArrArrayToObject(UnitTester $I)
{
$I->wantToTest('Helper\Arr - arrayToObject()');
$I->wantToTest('Helper\Arr - toObject()');

$source = [
'one' => 'two',
'three' => 'four',
];

$actual = Arr::arrayToObject($source);
$actual = Arr::toObject($source);

$expected = new stdClass();
$expected->one = 'two';
Expand Down