Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdulici committed Dec 30, 2021
1 parent 51f1d89 commit 3ed93d2
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions src/Support/SortableLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static function render(array $parameters): string

$title = self::applyFormatting($title, $sortColumn);

if ($mergeTitleAs = config('sortable.inject_title_as', null)) {
if ($mergeTitleAs = config('sortable.inject_title_as')) {
request()->merge([$mergeTitleAs => $title]);
}

Expand Down Expand Up @@ -60,7 +60,7 @@ public static function parseParameters(array $parameters): array
*/
public static function explodeSortParameter(string $parameter): array
{
$separator = config('sortable.relation_column_separator', '.');
$separator = config('sortable.relation_column_separator');

if (Str::contains($parameter, $separator)) {
$oneToOneSort = explode($separator, $parameter);
Expand Down Expand Up @@ -88,11 +88,11 @@ private static function applyFormatting($title, string $sortColumn)

if ($title === null) {
$title = $sortColumn;
} elseif (! config('sortable.format_custom_titles', true)) {
} elseif (! config('sortable.format_custom_titles')) {
return $title;
}

$formatting_function = config('sortable.formatting_function', null);
$formatting_function = config('sortable.formatting_function');
if (! is_null($formatting_function) && function_exists($formatting_function)) {
$title = call_user_func($formatting_function, $title);
}
Expand All @@ -106,15 +106,15 @@ private static function determineDirection($sortColumn, $sortParameter): array

if ((request()->get('sort') == $sortParameter) && in_array(request()->get('direction'), ['asc', 'desc'])) {
$icon .= (request()->get('direction') === 'asc')
? config('sortable.asc_suffix', '-asc')
: config('sortable.desc_suffix', '-desc');
? config('sortable.asc_suffix')
: config('sortable.desc_suffix');

$direction = request()->get('direction') === 'desc' ? 'asc' : 'desc';

return [$icon, $direction];
} else {
$icon = config('sortable.icons.sortable');
$direction = config('sortable.default_direction_unsorted', 'asc');
$direction = config('sortable.default_direction_unsorted');

return [$icon, $direction];
}
Expand All @@ -133,13 +133,16 @@ private static function selectIcon($sortColumn): string
return $icon;
}

private static function formTrailingTag(string $icon): string
/**
* @param string|null $icon
*/
private static function formTrailingTag($icon): string
{
if (! config('sortable.icons.enabled', true)) {
if (! config('sortable.icons.enabled')) {
return '</a>';
}

$clickableIcon = config('sortable.icons.clickable', false);
$clickableIcon = config('sortable.icons.clickable');
$trailingTag = static::getIconHtml($icon) . '</a>';

if ($clickableIcon === false) {
Expand All @@ -158,17 +161,17 @@ private static function getAnchorClass(string $sortColumn, array &$anchorAttribu
{
$class = [];

$anchorClass = config('sortable.anchor_class', null);
$anchorClass = config('sortable.anchor_class');
if ($anchorClass !== null) {
$class[] = $anchorClass;
}

$activeClass = config('sortable.active_anchor_class', null);
$activeClass = config('sortable.active_anchor_class');
if ($activeClass !== null && self::shouldShowActive($sortColumn)) {
$class[] = $activeClass;
}

$directionClassPrefix = config('sortable.direction_anchor_class_prefix', null);
$directionClassPrefix = config('sortable.direction_anchor_class_prefix');
if ($directionClassPrefix !== null && self::shouldShowActive($sortColumn)) {
$class[] = $directionClassPrefix . (request()->get('direction') === 'asc')
? config('sortable.asc_suffix', '-asc')
Expand Down

0 comments on commit 3ed93d2

Please sign in to comment.