Skip to content
This repository has been archived by the owner on Aug 13, 2023. It is now read-only.

Commit

Permalink
Merge pull request #2 from REZ1DENT3/dev
Browse files Browse the repository at this point in the history
hhvm patch
  • Loading branch information
rez1dent3 authored Jan 11, 2017
2 parents 9cf4cdd + a3dfc43 commit 1f0badf
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion demo/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@

var_dump($helper->arr()->get([
'name' => 'Max'
], 'name'));
], 'name'));
14 changes: 8 additions & 6 deletions src/Helper/Helpers/Arr/Arr.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Arr extends AbstractHelper
*
* @return array
*/
public function map(array $storage, callable $callback)
public function map(array $storage, $callback)
{
return array_map($callback, $storage);
}
Expand All @@ -28,11 +28,15 @@ public function map(array $storage, callable $callback)
*
* @return array
*/
public function filter(array $storage, callable $callback)
public function filter(array $storage, $callback)
{
if (defined('HHVM_VERSION'))
try
{
$array = []; // fixme : hhvm please
return array_filter($storage, $callback, ARRAY_FILTER_USE_BOTH);
}
catch (\Exception $exception)
{
$array = [];
foreach ($storage as $key => $value)
{
if ($callback($value, $key))
Expand All @@ -43,8 +47,6 @@ public function filter(array $storage, callable $callback)

return $array;
}

return array_filter($storage, $callback, ARRAY_FILTER_USE_BOTH);
}

/**
Expand Down
12 changes: 10 additions & 2 deletions tests/Tests/ArrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,18 @@ public function testFilterHHVM()

if (!defined('HHVM_VERSION'))
{
define('HHVM_VERSION', 1);
define('HHVM_VERSION', 'hhvm');
}

$this->testFilter();
$resultArray = $this->helper()->arr()->filter($this->array, function (&$var, $key)
{
return is_int($key);
});

foreach ($resultArray as $key => $value)
{
$this->assertTrue(is_int($key));
}

}

Expand Down

0 comments on commit 1f0badf

Please sign in to comment.