Skip to content

Commit

Permalink
code style
Browse files Browse the repository at this point in the history
  • Loading branch information
robsonvleite committed Oct 3, 2018
1 parent 414cbe4 commit 5f458ee
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions src/Paginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ class Paginator
/** @var int */
private $page;

/** @var int */
private $pages;

/** @var int */
private $rows;

Expand All @@ -31,6 +34,9 @@ class Paginator
/** @var string */
private $title;

/** @var string */
private $class;

/** @var string */
private $hash;

Expand All @@ -40,9 +46,6 @@ class Paginator
/** @var array */
private $last;

/** @var string */
private $cssClass;

/**
* Paginator constructor.
* @param string|null $link
Expand Down Expand Up @@ -103,16 +106,16 @@ public function offset(): int
*/
public function render(string $cssClass = "paginator"): ?string
{
$this->cssClass = $cssClass;
$this->class = $cssClass;
$this->pages = (int)ceil($this->rows / $this->limit);

if ($this->rows > $this->limit):
$pages = ceil($this->rows / $this->limit);
$paginator = "<nav class=\"{$this->cssClass}\">";
$paginator .= "<a class='{$this->cssClass}_item' title=\"{$this->first[0]}\" href=\"{$this->link}1{$this->hash}\">{$this->first[1]}</a>";
$paginator = "<nav class=\"{$this->class}\">";
$paginator .= "<a class='{$this->class}_item' title=\"{$this->first[0]}\" href=\"{$this->link}1{$this->hash}\">{$this->first[1]}</a>";
$paginator .= $this->beforePages();
$paginator .= "<span class=\"{$this->cssClass}_item {$this->cssClass}_active\">{$this->page}</span>";
$paginator .= $this->afterPages($pages);
$paginator .= "<a class='{$this->cssClass}_item' title=\"{$this->last[0]}\" href=\"{$this->link}{$pages}{$this->hash}\">{$this->last[1]}</a>";
$paginator .= "<span class=\"{$this->class}_item {$this->class}_active\">{$this->page}</span>";
$paginator .= $this->afterPages();
$paginator .= "<a class='{$this->class}_item' title=\"{$this->last[0]}\" href=\"{$this->link}{$this->pages}{$this->hash}\">{$this->last[1]}</a>";
$paginator .= "</nav>";
return $paginator;
endif;
Expand All @@ -128,7 +131,7 @@ private function beforePages(): ?string
$before = null;
for ($iPag = $this->page - $this->range; $iPag <= $this->page - 1; $iPag++):
if ($iPag >= 1):
$before .= "<a class='{$this->cssClass}_item' title=\"{$this->title} {$iPag}\" href=\"{$this->link}{$iPag}{$this->hash}\">{$iPag}</a>";
$before .= "<a class='{$this->class}_item' title=\"{$this->title} {$iPag}\" href=\"{$this->link}{$iPag}{$this->hash}\">{$iPag}</a>";
endif;
endfor;

Expand All @@ -139,12 +142,12 @@ private function beforePages(): ?string
* @param int $pages
* @return null|string
*/
private function afterPages(int $pages): ?string
private function afterPages(): ?string
{
$after = null;
for ($dPag = $this->page + 1; $dPag <= $this->page + $this->range; $dPag++):
if ($dPag <= $pages):
$after .= "<a class='{$this->cssClass}_item' title=\"{$this->title} {$dPag}\" href=\"{$this->link}{$dPag}{$this->hash}\">{$dPag}</a>";
if ($dPag <= $this->pages):
$after .= "<a class='{$this->class}_item' title=\"{$this->title} {$dPag}\" href=\"{$this->link}{$dPag}{$this->hash}\">{$dPag}</a>";
endif;
endfor;

Expand Down

0 comments on commit 5f458ee

Please sign in to comment.