Completed
Push — develop ( aad3f3...839a66 )
by Zack
15:14 queued 02:19
created

GravityView_Widget_Page_Links::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 0
dl 0
loc 14
ccs 9
cts 9
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 8 and the first side effect is on line 76.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
/**
4
 * Widget to display page links
5
 *
6
 * @extends GravityView_Widget
7
 */
8
class GravityView_Widget_Page_Links extends \GV\Widget {
9
10
	protected $show_on_single = false;
11
12 2
	function __construct() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
13
14 2
		$this->widget_description = __('Links to multiple pages of results.', 'gravityview' );
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
15
16 2
		$default_values = array( 'header' => 1, 'footer' => 1 );
17 2
		$settings = array( 'show_all' => array(
0 ignored issues
show
introduced by
The first index in a multi-value array must be on a new line
Loading history...
introduced by
The first value in a multi-value array must be on a new line
Loading history...
18 2
			'type' => 'checkbox',
19 2
			'label' => __( 'Show each page number', 'gravityview' ),
20 2
			'desc' => __('Show every page number instead of summary (eg: 1 2 3 ... 8 »)', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
21
			'value' => false
0 ignored issues
show
introduced by
Each line in an array declaration must end in a comma
Loading history...
22
		));
23 2
		parent::__construct( __( 'Page Links', 'gravityview' ) , 'page_links', $default_values, $settings );
24
25 2
	}
26
27 1
	public function render_frontend( $widget_args, $content = '', $context = '') {
28 1
		$gravityview_view = GravityView_View::getInstance();
29
30 1
		if( !$this->pre_render_frontend() ) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
31
			return;
32
		}
33
34 1
		$atts = shortcode_atts( array(
35 1
			'page_size' => \GV\Utils::get( $gravityview_view->paging, 'page_size' ),
0 ignored issues
show
Documentation introduced by
The property $paging is declared protected in GravityView_View. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
36 1
			'total' => $gravityview_view->total_entries,
0 ignored issues
show
Documentation introduced by
The property $total_entries is declared protected in GravityView_View. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
37 1
			'show_all' => !empty( $this->settings['show_all']['default'] ),
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
38 1
			'current' => (int) \GV\Utils::_GET( 'pagenum', 1 ),
39 1
		), $widget_args, 'gravityview_widget_page_links' );
40
		
41
		$page_link_args = array(
42 1
			'base' => add_query_arg('pagenum','%#%', gv_directory_link() ),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
43 1
			'format' => '&pagenum=%#%',
44
			'add_args' => array(), //
45 1
			'prev_text' => '&laquo;',
46 1
			'next_text' => '&raquo;',
47 1
			'type' => 'list',
48 1
			'end_size' => 1,
49 1
			'mid_size' => 2,
50 1
			'total' => empty( $atts['page_size'] ) ? 0 : ceil( $atts['total'] / $atts['page_size'] ),
51 1
			'current' => $atts['current'],
52 1
			'show_all' => !empty( $atts['show_all'] ), // to be available at backoffice
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
53
		);
54
55
		/**
56
		 * @filter `gravityview_page_links_args` Filter the pagination options
57
		 * @since 1.1.4
58
		 * @param array  $page_link_args Array of arguments for the `paginate_links()` function. [Read more about `paginate_links()`](http://developer.wordpress.org/reference/functions/paginate_links/)
59
		 */
60 1
		$page_link_args = apply_filters('gravityview_page_links_args', $page_link_args );
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
61
62 1
		$page_links = paginate_links( $page_link_args );
63
64 1
		if( !empty( $page_links )) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
introduced by
No space before closing parenthesis is prohibited
Loading history...
65 1
			$class = !empty( $widget_args['custom_class'] ) ? $widget_args['custom_class'] : '';
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
66 1
			$class = gravityview_sanitize_html_class( 'gv-widget-page-links ' . $class );
67 1
			echo '<div class="'.$class.'">'. $page_links .'</div>';
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$class'
Loading history...
introduced by
Expected next thing to be a escaping function, not '$page_links'
Loading history...
68
		} else {
69
			gravityview()->log->debug( 'No page links; paginate_links() returned empty response.' );
70
		}
71
72 1
	}
73
74
}
75
76
new GravityView_Widget_Page_Links;