Skip to content

Commit

Permalink
Merge pull request #51 from pratiksh404/analysis-16Do6P
Browse files Browse the repository at this point in the history
Apply fixes from StyleCI
  • Loading branch information
pratiksh404 authored Jul 10, 2023
2 parents 588b62c + 50afeb0 commit 4a82dc8
Showing 1 changed file with 50 additions and 50 deletions.
100 changes: 50 additions & 50 deletions src/Helpers/AdminHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
use Illuminate\Support\Str;
use Pratiksh\Adminetic\Models\Admin\Setting;

if (!function_exists('spa')) {
if (! function_exists('spa')) {
function spa()
{
return setting('spa', config('adminetic.spa', true));
}
}

if (!function_exists('getClassesList')) {
if (! function_exists('getClassesList')) {
function getClassesList($dir)
{
$classes = \File::allFiles($dir);
Expand All @@ -26,7 +26,7 @@ function getClassesList($dir)
return $classes;
}
}
if (!function_exists('getAllModelNames')) {
if (! function_exists('getAllModelNames')) {
function getAllModelNames($dir)
{
$modelNames = [];
Expand All @@ -40,128 +40,128 @@ function getAllModelNames($dir)
}
}

if (!function_exists('validImageFolder')) {
if (! function_exists('validImageFolder')) {
function validImageFolder($name, $default = 'default')
{
return strtolower(str_replace([' ', '-', '$', '<', '>', '&', '{', '*', '\\', '/', ':', '.', ';', ',', "'", '"'], '_', $name ?? trim($default)));
}
}

if (!function_exists('getImagePlaceholder')) {
if (! function_exists('getImagePlaceholder')) {
function getImagePlaceholder()
{
return asset(config('adminetic.default_image_placeholder', 'adminetic/static/placeholder.png'));
}
}

if (!function_exists('getVerticalImagePlaceholder')) {
if (! function_exists('getVerticalImagePlaceholder')) {
function getVerticalImagePlaceholder()
{
return asset(config('adminetic.vertical_image_placeholder', 'adminetic/static/vertical_placeholder.jpg'));
}
}

if (!function_exists('getSliderPlaceholder')) {
if (! function_exists('getSliderPlaceholder')) {
function getSliderPlaceholder()
{
return asset(config('adminetic.slider_placeholder', 'adminetic/static/slider.jpg'));
}
}

if (!function_exists('getProfilePlaceholder')) {
if (! function_exists('getProfilePlaceholder')) {
function getProfilePlaceholder($p = null)
{
$profile = $p ?? Auth::user()->profile ?? Auth::user()->profile()->create();

return isset($profile->profile_pic) ? (Illuminate\Support\Str::contains($profile->profile_pic, ['https://', 'http://']) ? $profile->profile_pic : asset('storage/' . $profile->profile_pic)) : asset(config('adminetic.profile_placeholder', 'adminetic/static/profile.gif'));
return isset($profile->profile_pic) ? (Illuminate\Support\Str::contains($profile->profile_pic, ['https://', 'http://']) ? $profile->profile_pic : asset('storage/'.$profile->profile_pic)) : asset(config('adminetic.profile_placeholder', 'adminetic/static/profile.gif'));
}
}

if (!function_exists('title')) {
if (! function_exists('title')) {
function title()
{
return setting('title', config('adminetic.name', 'Adminetic'));
}
}

if (!function_exists('description')) {
if (! function_exists('description')) {
function description($default = null)
{
return setting('description', config('adminetic.description', $default ?? 'Adminetic Admin Panel'));
}
}

if (!function_exists('keywords')) {
if (! function_exists('keywords')) {
function keywords()
{
return setting('keywords', config('adminetic.keywords', 'adminetic admin panel, adminetic, pratik shrestha, doctype innovations'));
}
}

if (!function_exists('loader_enabled')) {
if (! function_exists('loader_enabled')) {
function loader_enabled()
{
return setting('loader_enabled', config('adminetic.loader_enabled', true));
}
}

if (!function_exists('favicon')) {
if (! function_exists('favicon')) {
function favicon()
{
return getImg(!is_null(setting('favicon')) ? setting('favicon', config('adminetic.favicon', 'adminetic/static/favicon.png')) : config('adminetic.favicon', 'adminetic/static/favicon.png'), config('adminetic.favicon', 'adminetic/static/favicon.png'));
return getImg(! is_null(setting('favicon')) ? setting('favicon', config('adminetic.favicon', 'adminetic/static/favicon.png')) : config('adminetic.favicon', 'adminetic/static/favicon.png'), config('adminetic.favicon', 'adminetic/static/favicon.png'));
}
}

if (!function_exists('logo')) {
if (! function_exists('logo')) {
function logo()
{
return getImg(!is_null(setting('logo')) ? setting('logo', config('adminetic.logo', 'adminetic/static/logo.png')) : config('adminetic.logo', 'adminetic/static/logo.png'), config('adminetic.logo', 'adminetic/static/logo.png'));
return getImg(! is_null(setting('logo')) ? setting('logo', config('adminetic.logo', 'adminetic/static/logo.png')) : config('adminetic.logo', 'adminetic/static/logo.png'), config('adminetic.logo', 'adminetic/static/logo.png'));
}
}

if (!function_exists('dark_logo')) {
if (! function_exists('dark_logo')) {
function dark_logo()
{
return getImg(!is_null(setting('dark_logo')) ? setting('dark_logo', config('adminetic.dark_logo', 'adminetic/static/dark_logo.png')) : config('adminetic.dark_logo', 'adminetic/static/dark_logo.png'), config('adminetic.dark_logo', 'adminetic/static/dark_logo.png'));
return getImg(! is_null(setting('dark_logo')) ? setting('dark_logo', config('adminetic.dark_logo', 'adminetic/static/dark_logo.png')) : config('adminetic.dark_logo', 'adminetic/static/dark_logo.png'), config('adminetic.dark_logo', 'adminetic/static/dark_logo.png'));
}
}

if (!function_exists('logoBanner')) {
if (! function_exists('logoBanner')) {
function logoBanner()
{
return getImg(!is_null(setting('logo_banner')) ? setting('logo_banner', config('adminetic.logo_banner', 'adminetic/static/logo_banner.jpg')) : config('adminetic.logo_banner', 'adminetic/static/logo_banner.jpg'), config('adminetic.logo_banner', 'adminetic/static/logo_banner.jpg'));
return getImg(! is_null(setting('logo_banner')) ? setting('logo_banner', config('adminetic.logo_banner', 'adminetic/static/logo_banner.jpg')) : config('adminetic.logo_banner', 'adminetic/static/logo_banner.jpg'), config('adminetic.logo_banner', 'adminetic/static/logo_banner.jpg'));
}
}

if (!function_exists('login_register_bg_image')) {
if (! function_exists('login_register_bg_image')) {
function login_register_bg_image()
{
return getImg(!is_null(setting('login_register_bg_image')) ? setting('login_register_bg_image', config('adminetic.login_register_bg_img', 'adminetic/static/login_register_bg_img.jpg')) : config('adminetic.login_register_bg_img', 'adminetic/static/login_register_bg_img.jpg'), config('adminetic.login_register_bg_img', 'adminetic/static/login_register_bg_img.jpg'));
return getImg(! is_null(setting('login_register_bg_image')) ? setting('login_register_bg_image', config('adminetic.login_register_bg_img', 'adminetic/static/login_register_bg_img.jpg')) : config('adminetic.login_register_bg_img', 'adminetic/static/login_register_bg_img.jpg'), config('adminetic.login_register_bg_img', 'adminetic/static/login_register_bg_img.jpg'));
}
}

if (!function_exists('getLazyLoadImg')) {
if (! function_exists('getLazyLoadImg')) {
function getLazyLoadImg()
{
return asset('adminetic/static/loader.svg');
}
}

if (!function_exists('random_color_part')) {
if (! function_exists('random_color_part')) {
function random_color_part()
{
return str_pad(dechex(mt_rand(0, 255)), 2, '0', STR_PAD_LEFT);
}
}

if (!function_exists('random_color')) {
if (! function_exists('random_color')) {
function random_color()
{
return random_color_part() . random_color_part() . random_color_part();
return random_color_part().random_color_part().random_color_part();
}
}

if (!function_exists('setting')) {
if (! function_exists('setting')) {
function setting($setting_name, $default = null)
{
$valid_setting_name = strtolower(str_replace(' ', '_', $setting_name));
Expand All @@ -171,7 +171,7 @@ function setting($setting_name, $default = null)
}
}

if (!function_exists('preference')) {
if (! function_exists('preference')) {
function preference($preference_name, bool $default = null)
{
$valid_preference_name = strtolower(str_replace(' ', '_', $preference_name));
Expand All @@ -185,39 +185,39 @@ function preference($preference_name, bool $default = null)
}
}

if (!function_exists('deleteImage')) {
if (! function_exists('deleteImage')) {
function deleteImage($image)
{
$image ? (\Illuminate\Support\Facades\File::exists(public_path('storage/' . $image)) ? \Illuminate\Support\Facades\File::delete(public_path('storage/' . $image)) : '') : '';
$image ? (\Illuminate\Support\Facades\File::exists(public_path('storage/'.$image)) ? \Illuminate\Support\Facades\File::delete(public_path('storage/'.$image)) : '') : '';
}
}

if (!function_exists('api_paginate_limit')) {
if (! function_exists('api_paginate_limit')) {
function api_paginate_limit($default = null)
{
return setting('api_paginate_limit', $default ?? config('adminetic.api_paginate_limit', 10));
}
}

if (!function_exists('api_collection_return_paginate')) {
if (! function_exists('api_collection_return_paginate')) {
function api_collection_return_paginate()
{
return setting('api_collection_return_paginate', config('adminetic.api_collection_return_paginate', true));
}
}

if (!function_exists('darkMode')) {
if (! function_exists('darkMode')) {
function darkMode()
{
return setting('dark_mode', config('adminetic.dark_mode', false));
}
}

if (!function_exists('getCondition')) {
if (! function_exists('getCondition')) {
function getCondition($conditions)
{
$result = null;
if (!isset($conditions)) {
if (! isset($conditions)) {
return false;
}

Expand All @@ -243,12 +243,12 @@ function getCondition($conditions)
}
}

if (!function_exists('getImg')) {
if (! function_exists('getImg')) {
function getImg($img, $default)
{
if (isset($img)) {
if (file_exists(public_path('storage/' . $img))) {
return asset('storage/' . $img);
if (file_exists(public_path('storage/'.$img))) {
return asset('storage/'.$img);
} elseif (file_exists(public_path($img))) {
return asset($img);
} else {
Expand All @@ -260,10 +260,10 @@ function getImg($img, $default)
}
}

if (!function_exists('putContentToClassFunction')) {
if (! function_exists('putContentToClassFunction')) {
function putContentToClassFunction($file, $function_name, $data, $closing_token = '}')
{
$data = $data . "\n";
$data = $data."\n";
// Read the contents of the file into a string
$contents = file_get_contents($file);

Expand All @@ -283,7 +283,7 @@ function putContentToClassFunction($file, $function_name, $data, $closing_token
$function_definition = substr($contents, $start_pos, $end_pos - $start_pos + 1);

// Append the new content to the function definition
$modified_function_definition = rtrim($function_definition, $closing_token) . $data . $closing_token;
$modified_function_definition = rtrim($function_definition, $closing_token).$data.$closing_token;

// Replace the original function definition with the modified one in the class definition
$modified_contents = substr_replace($contents, $modified_function_definition, $start_pos, $end_pos - $start_pos + 1);
Expand All @@ -295,7 +295,7 @@ function putContentToClassFunction($file, $function_name, $data, $closing_token
}
}

if (!function_exists('checkIfFieldIsRequired')) {
if (! function_exists('checkIfFieldIsRequired')) {
function checkIfFieldIsRequired($table_name, $field)
{
$isNullable = null;
Expand All @@ -312,11 +312,11 @@ function checkIfFieldIsRequired($table_name, $field)
}
}

if (!function_exists('label')) {
if (! function_exists('label')) {
function label($table, $field, $default_label = null)
{
$display_name = $default_label ?? Str::ucfirst(str_replace('_', ' ', $field));
if (!checkIfFieldIsRequired($table, $field)) {
if (! checkIfFieldIsRequired($table, $field)) {
// do something if phone_number is nullable
echo "{$display_name} <span class='text-danger'>*</span>";
} else {
Expand All @@ -325,20 +325,20 @@ function label($table, $field, $default_label = null)
}
}

if (!function_exists('role_theme')) {
if (! function_exists('role_theme')) {
function role_theme()
{
$role = auth()->check() ? auth()->user()->roles->first()->name : null;
$role_theme = config('adminetic.role_theme', null);
if (!is_null($role_theme)) {
if (! is_null($role_theme)) {
return isset($role_theme[$role]) ? $role_theme[$role] : 'compact-sidebar';
}

return 'compact-sidebar';
}
}

if (!function_exists('setEnvValue')) {
if (! function_exists('setEnvValue')) {
function setEnvValue(array $values)
{
$envFile = app()->environmentFilePath();
Expand All @@ -352,7 +352,7 @@ function setEnvValue(array $values)
$oldLine = substr($str, $keyPosition, $endOfLinePosition - $keyPosition);

// If key does not exist, add it
if (!$keyPosition || !$endOfLinePosition || !$oldLine) {
if (! $keyPosition || ! $endOfLinePosition || ! $oldLine) {
$str .= "{$envKey}={$envValue}\n";
} else {
$str = str_replace($oldLine, "{$envKey}={$envValue}", $str);
Expand All @@ -361,7 +361,7 @@ function setEnvValue(array $values)
}

$str = substr($str, 0, -1);
if (!file_put_contents($envFile, $str)) {
if (! file_put_contents($envFile, $str)) {
return false;
}

Expand Down

0 comments on commit 4a82dc8

Please sign in to comment.