CliExpandPager::render()   B
last analyzed

Complexity

Conditions 10
Paths 97

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 10

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 10
eloc 11
c 1
b 0
f 0
nc 97
nop 1
dl 0
loc 19
ccs 12
cts 12
cp 1
crap 10
rs 7.6666

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace kalanis\kw_paging\Render;
4
5
6
/**
7
 * Class CliExpandPager
8
 * @package kalanis\kw_paging\Render
9
 * Pager for displaying on CLI
10
 */
11
class CliExpandPager extends CliPager
12
{
13 4
    public function render(bool $showPositions = true): string
14
    {
15 4
        if (!$this->getPositions()->prevPageExists() && !$this->getPositions()->nextPageExists()) {
16 1
            return $this->getFilledText($this->getPositions());
17
        }
18 3
        $pages = [];
19
20 3
        $pages[] = $this->getPositions()->prevPageExists() ? static::PREV_PAGE . static::PREV_PAGE . ' ' . $this->getPositions()->getFirstPage() : static::NONE_PAGE . static::NONE_PAGE ;
21 3
        $pages[] = $this->getPositions()->prevPageExists() ? static::PREV_PAGE . ' ' . $this->getPositions()->getPrevPage() : static::NONE_PAGE ;
22
23 3
        foreach ($this->getDisplayPages() as $displayPage) {
24 3
            $current = ($this->getPositions()->getPager()->getActualPage() == $displayPage);
25 3
            $pages[] = $current ? static::SELECT_PAGE . $displayPage . static::SELECT_PAGE : $displayPage ;
26
        }
27
28 3
        $pages[] = $this->getPositions()->nextPageExists() ? $this->getPositions()->getNextPage() . ' ' . static::NEXT_PAGE : static::NONE_PAGE ;
29 3
        $pages[] = $this->getPositions()->nextPageExists() ? $this->getPositions()->getLastPage() . ' ' . static::NEXT_PAGE . static::NEXT_PAGE : static::NONE_PAGE . static::NONE_PAGE ;
30
31 3
        return implode(' | ', $pages) . ( $showPositions ? (PHP_EOL . $this->getFilledText($this->getPositions()) ) : '');
32
    }
33
}
34