for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace Greenlyst\BaseCommerce\Core;
use function ArrayHelpers\array_has;
use Greenlyst\BaseCommerce\LogicException;
class Helpers
{
/**
* @param $data
*
* @return array
*/
public static function clearArray($data)
return array_filter($data, function ($item) {
if ($item === null) {
return false;
}
return true;
});
* @param $array
* @param $keys
* @throws LogicException
public static function validateArray($array, $keys)
foreach ($keys as $key) {
if (array_has($array, $key) == false) {
===
When comparing two booleans, it is generally considered safer to use the strict comparison operator.
throw LogicException::requiredFieldDoesntExist($key);
* Get all of the given array except for a specified array of items.
* @param array $array
* @param array|string $keys
public static function array_except($array, $keys)
return array_diff_key($array, array_flip((array) $keys));
public static function replaceArrayKeys($array, $search, $replace)
$newArray = [];
foreach ($array as $key => $item) {
$newArray[str_replace($search, $replace, $key)] = $item;
return $newArray;
When comparing two booleans, it is generally considered safer to use the strict comparison operator.