Passed
Push — master ( 6375bf...7ef419 )
by Paul
05:58
created

Pagination::buildLinksForDeprecatedThemes()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
cc 4
eloc 12
nc 5
nop 0
dl 0
loc 18
ccs 0
cts 18
cp 0
crap 20
rs 9.8666
c 0
b 0
f 0
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Modules\Html\Partials;
4
5
use GeminiLabs\SiteReviews\Contracts\PartialContract;
6
use GeminiLabs\SiteReviews\Database\QueryBuilder;
7
use GeminiLabs\SiteReviews\Modules\Html\Template;
8
use GeminiLabs\SiteReviews\Modules\Style;
9
10
class Pagination implements PartialContract
11
{
12
	/**
13
	 * @var array
14
	 */
15
	protected $args;
16
17
	/**
18
	 * @return void|string
19
	 */
20
	public function build( array $args = [] )
21
	{
22
		$this->args = $this->normalize( $args );
23
		if( $this->args['total'] < 2 )return;
24
		return glsr( Template::class )->build( 'templates/pagination', [
25
			'context' => [
26
				'links' => apply_filters( 'site-reviews/paginate_links', $this->buildLinks(), $this->args ),
27
				'loader' => '<div class="glsr-loader"></div>',
28
				'screen_reader_text' => __( 'Site Reviews navigation', 'site-reviews' ),
29
			],
30
		]);
31
	}
32
33
	/**
34
	 * @return string
35
	 */
36
	protected function buildLinks()
37
	{
38
		$args = glsr( Style::class )->paginationArgs([
39
			'current' => $this->args['paged'],
40
			'total' => $this->args['total'],
41
		]);
42
		if( is_front_page() ) {
43
			unset( $args['format'] );
44
		}
45
		$args = apply_filters( 'site-reviews/paginate_links/args', $args, $this->args );
46
		return paginate_links( $args );
0 ignored issues
show
Bug Best Practice introduced by
The expression return paginate_links($args) also could return the type array|string[] which is incompatible with the documented return type string.
Loading history...
47
	}
48
49
	/**
50
	 * @return array
51
	 */
52
	protected function normalize( array $args )
53
	{
54
		return wp_parse_args( $args, [
55
			'paged' => glsr( QueryBuilder::class )->getPaged(),
56
			'total' => 1,
57
		]);
58
	}
59
}
60