Skip to content

Commit

Permalink
Moved elementsNotBlank function to ArrayUtil class
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcage committed Sep 21, 2022
1 parent bf7da9b commit 8ea59ac
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 21 deletions.
24 changes: 24 additions & 0 deletions app/Util/ArrayUtil.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace App\Util;

class ArrayUtil
{
/**
* Checks if the array contains non-blank values specified by the given keys.
*
* @param array $array the array to be checked
* @param array $keys the keys to be considered
* @return bool if all values indicated by the specified keys are not blank
*/
public static function elementsNotBlank(array $array, array $keys): bool
{
foreach ($keys as $key) {
if (!filled($array[$key])) {
return false;
}
}

return true;
}
}
3 changes: 2 additions & 1 deletion app/View/Components/OauthButtons.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\View\Components;

use App\Util\ArrayUtil;
use Illuminate\View\Component;

class OauthButtons extends Component
Expand All @@ -22,7 +23,7 @@ private function getOauthServices(): array
{
return collect(config('auth.socialite.drivers'))
->filter(fn (string $driver) => config('services.'.$driver) !== null
&& array_elements_not_blank(config('services.'.$driver), ['client_id', 'client_secret', 'redirect']))
&& ArrayUtil::elementsNotBlank(config('services.'.$driver), ['client_id', 'client_secret', 'redirect']))
->map(fn (string $driver) => [
'name' => $driver,
'icon' => $driver,
Expand Down
20 changes: 0 additions & 20 deletions app/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,6 @@ function whatsapp_link(string $value, ?string $text = null): string
}
}

if (! function_exists('array_elements_not_blank')) {
/**
* Checks if the array contains non-blank values specified by the given keys.
*
* @param array $array the array to be checked
* @param array $keys the keys to be considered
* @return bool if all values indicated by the specified keys are not blank
*/
function array_elements_not_blank(array $array, array $keys): bool
{
foreach ($keys as $key) {
if (! filled($array[$key])) {
return false;
}
}

return true;
}
}

if (! function_exists('randomPercentages')) {
function randomPercentages(int $num): array
{
Expand Down

0 comments on commit 8ea59ac

Please sign in to comment.