Skip to content

Commit

Permalink
Fix codeclimate
Browse files Browse the repository at this point in the history
  • Loading branch information
arxeiss committed Jan 29, 2020
1 parent 152167b commit fea825f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .codeclimate.yml
@@ -0,0 +1,5 @@
version: "2"
checks:
argument-count:
config:
threshold: 8
8 changes: 5 additions & 3 deletions Makefile
@@ -1,6 +1,6 @@
#!make

all:
help:
@echo "Project aliases and shortcuts."

@echo "\nTests"
Expand All @@ -12,8 +12,10 @@ all:
@echo " make lint - Run CodeSniffer Beautifier"
@echo " make phpstan - Run PHP STAN"

help:
make all
all:
make lint
make phpstan
make test

test:
./vendor/bin/phpunit $(TESTS)
Expand Down
40 changes: 28 additions & 12 deletions src/Paginator.php
Expand Up @@ -173,18 +173,7 @@ protected function applyBreakpointClasses(
return $paginator;
}

// Search index of active element
$middleIndex = self::arrayCallbackSearch($buttons, static function ($button) {
return $button->active === true;
});
// Search for index of the left dots element - there will be max 1 dots element on the left from middle index
$leftDotsIndex = self::arrayCallbackSearch($buttons, static function ($button, $key) use ($middleIndex) {
return $button->dots && $key < $middleIndex;
});
// Search for index of the right dots element - there will be max 1 dots element on the right from middle index
$rightDotsIndex = self::arrayCallbackSearch($buttons, static function ($button, $key) use ($middleIndex) {
return $button->dots && $key > $middleIndex;
});
[$leftDotsIndex, $middleIndex, $rightDotsIndex] = $this->getDotsIndex($paginator);

// There are no dots on the left side but breakpoint should hide some of the elements on the left side
if (!$leftDotsIndex && $this->currentPage > (int)\ceil($maxVisible / 2)) {
Expand Down Expand Up @@ -239,6 +228,33 @@ protected function applyBreakpointClasses(
return $paginator;
}

/**
* @return array<int>
*/
protected function getDotsIndex(Pages $paginator): array
{
// Search index of active element
$middleIndex = self::arrayCallbackSearch($paginator->buttons, static function ($button) {
return $button->active === true;
});
// Search for index of the left dots element - there will be max 1 dots element on the left from middle index
$leftDotsIndex = self::arrayCallbackSearch(
$paginator->buttons,
static function ($button, $key) use ($middleIndex) {
return $button->dots && $key < $middleIndex;
}
);
// Search for index of the right dots element - there will be max 1 dots element on the right from middle index
$rightDotsIndex = self::arrayCallbackSearch(
$paginator->buttons,
static function ($button, $key) use ($middleIndex) {
return $button->dots && $key > $middleIndex;
}
);

return [$leftDotsIndex, $middleIndex, $rightDotsIndex];
}

/**
* Search index in array by condition in callback
*
Expand Down

0 comments on commit fea825f

Please sign in to comment.