Conditions | 2 |
Paths | 2 |
Total Lines | 6 |
Code Lines | 3 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 1 | Features | 0 |
Metric | Value |
---|---|
cc | 2 |
eloc | 3 |
c | 2 |
b | 1 |
f | 0 |
nc | 2 |
nop | 0 |
dl | 0 |
loc | 6 |
rs | 10 |
1 | <?php |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
2 | |||
3 | namespace PodloveSubscribeButton; |
||
4 | |||
5 | include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
||
0 ignored issues
–
show
|
|||
6 | |||
7 | class Podlove_Subscribe_Button_Widget extends \WP_Widget { |
||
0 ignored issues
–
show
Class name "Podlove_Subscribe_Button_Widget" is not in PascalCase format
Classes in PHP are usually named in CamelCase. In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. The whole name starts with a capital letter as well. Thus the name database provider becomes ![]() |
|||
8 | |||
9 | public function __construct() { |
||
0 ignored issues
–
show
|
|||
10 | parent::__construct( |
||
11 | 'podlove_subscribe_button_wp_plugin_widget', |
||
0 ignored issues
–
show
|
|||
12 | ( self::is_podlove_publisher_active() ? 'Podlove Subscribe Button (WordPress plugin)' : 'Podlove Subscribe Button' ), |
||
0 ignored issues
–
show
|
|||
13 | array( 'description' => __( 'Adds a Podlove Subscribe Button to your Sidebar', 'podlove-subscribe-button' ), ) |
||
0 ignored issues
–
show
|
|||
14 | ); |
||
0 ignored issues
–
show
|
|||
15 | } |
||
0 ignored issues
–
show
|
|||
16 | |||
17 | public static $widget_settings = array('infotext', 'title', 'size', 'style', 'format', 'autowidth', 'button', 'color'); |
||
0 ignored issues
–
show
|
|||
18 | |||
19 | public static function is_podlove_publisher_active() { |
||
0 ignored issues
–
show
|
|||
20 | if ( is_plugin_active("podlove-podcasting-plugin-for-wordpress/podlove.php") ) { |
||
0 ignored issues
–
show
The string literal
podlove-podcasting-plugi...r-wordpress/podlove.php does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. ![]() |
|||
21 | return true; |
||
22 | } |
||
23 | |||
24 | return false; |
||
25 | } |
||
0 ignored issues
–
show
|
|||
26 | |||
27 | public function widget( $args, $instance ) { |
||
0 ignored issues
–
show
|
|||
28 | // Fetch the (network)button by it's name |
||
0 ignored issues
–
show
|
|||
29 | if ( ! $button = \PodloveSubscribeButton\Model\Button::get_button_by_name($instance['button']) ) |
||
0 ignored issues
–
show
|
|||
30 | return sprintf( __('Oops. There is no button with the ID "%s".', 'podlove-subscribe-button'), $args['button'] ); |
||
0 ignored issues
–
show
|
|||
31 | |||
32 | echo $args['before_widget']; |
||
0 ignored issues
–
show
|
|||
33 | echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ). $args['after_title']; |
||
0 ignored issues
–
show
|
|||
34 | |||
35 | echo $button->render( |
||
0 ignored issues
–
show
|
|||
36 | \PodloveSubscribeButton::get_array_value_with_fallback($instance, 'size'), |
||
0 ignored issues
–
show
|
|||
37 | \PodloveSubscribeButton::get_array_value_with_fallback($instance, 'autowidth'), |
||
0 ignored issues
–
show
|
|||
38 | \PodloveSubscribeButton::get_array_value_with_fallback($instance, 'style'), |
||
0 ignored issues
–
show
|
|||
39 | \PodloveSubscribeButton::get_array_value_with_fallback($instance, 'format'), |
||
0 ignored issues
–
show
|
|||
40 | \PodloveSubscribeButton::get_array_value_with_fallback($instance, 'color') |
||
0 ignored issues
–
show
|
|||
41 | ); |
||
0 ignored issues
–
show
|
|||
42 | |||
43 | if ( strlen($instance['infotext']) ) |
||
0 ignored issues
–
show
|
|||
44 | echo wpautop($instance['infotext']); |
||
0 ignored issues
–
show
|
|||
45 | |||
46 | echo $args['after_widget']; |
||
0 ignored issues
–
show
|
|||
47 | } |
||
0 ignored issues
–
show
|
|||
48 | |||
49 | public function form( $instance ) { |
||
0 ignored issues
–
show
|
|||
50 | |||
51 | $title = isset( $instance[ 'title' ] ) ? $instance[ 'title' ] : ''; |
||
0 ignored issues
–
show
|
|||
52 | $button = isset( $instance[ 'button' ] ) ? $instance[ 'button' ] : ''; |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
53 | $size = isset( $instance[ 'size' ] ) ? $instance[ 'size' ] : 'big'; |
||
0 ignored issues
–
show
|
|||
54 | $style = isset( $instance[ 'style' ] ) ? $instance[ 'style' ] : 'filled'; |
||
0 ignored issues
–
show
|
|||
55 | $format = isset( $instance[ 'format' ] ) ? $instance[ 'format' ] : 'cover'; |
||
0 ignored issues
–
show
|
|||
56 | $autowidth = isset( $instance[ 'autowidth' ] ) ? $instance[ 'autowidth' ] : true; |
||
0 ignored issues
–
show
|
|||
57 | $infotext = isset( $instance[ 'infotext' ] ) ? $instance[ 'infotext' ] : ''; |
||
0 ignored issues
–
show
|
|||
58 | $color = isset( $instance[ 'color' ] ) ? $instance[ 'color' ] : '#75ad91'; |
||
0 ignored issues
–
show
|
|||
59 | |||
60 | $buttons = \PodloveSubscribeButton\Model\Button::all(); |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 13 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
61 | if ( is_multisite() ) |
||
0 ignored issues
–
show
|
|||
62 | $network_buttons = \PodloveSubscribeButton\Model\NetworkButton::all(); |
||
63 | ?> |
||
64 | <p> |
||
65 | <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title', 'podlove-subscribe-button' ); ?></label> |
||
0 ignored issues
–
show
|
|||
66 | <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo esc_attr($title); ?>" /> |
||
0 ignored issues
–
show
|
|||
67 | |||
68 | <label for="<?php echo $this->get_field_id( 'color' ); ?>"><?php _e( 'Color', 'podlove-subscribe-button' ); ?></label> |
||
0 ignored issues
–
show
|
|||
69 | <input class="podlove_subscribe_button_color" id="<?php echo $this->get_field_id( 'color' ); ?>" name="<?php echo $this->get_field_name( 'color' ); ?>" value="<?php echo esc_attr($color); ?>" /> |
||
0 ignored issues
–
show
|
|||
70 | <style type="text/css"> |
||
71 | .sp-replacer { |
||
72 | display: flex; |
||
73 | } |
||
74 | .sp-preview { |
||
75 | flex-grow: 10; |
||
76 | } |
||
77 | </style> |
||
78 | |||
79 | <label for="<?php echo $this->get_field_id( 'button' ); ?>"><?php _e( 'Button', 'podlove-subscribe-button' ); ?></label> |
||
0 ignored issues
–
show
|
|||
80 | <select class="widefat" id="<?php echo $this->get_field_id( 'button' ); ?>" |
||
0 ignored issues
–
show
|
|||
81 | name="<?php echo $this->get_field_name( 'button' ); ?>"> |
||
0 ignored issues
–
show
|
|||
82 | <?php if ( isset($network_buttons) && count($network_buttons) > 0 ) : ?> |
||
0 ignored issues
–
show
|
|||
83 | <optgroup label="<?php _e('Local', 'podlove'); ?>"> |
||
0 ignored issues
–
show
|
|||
84 | <?php |
||
85 | foreach ($buttons as $subscribebutton) { |
||
0 ignored issues
–
show
|
|||
86 | echo "<option value='" . sanitize_title($subscribebutton->name) . "' " . selected( sanitize_title($subscribebutton->name), $button ) . " >" . sanitize_title($subscribebutton->title) . " (" . sanitize_title($subscribebutton->name) . ")</option>"; |
||
0 ignored issues
–
show
The string literal
> does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. ![]() The string literal
( does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. ![]() The string literal
)</option> does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. ![]() |
|||
87 | } |
||
88 | ?> |
||
89 | </optgroup> |
||
90 | <optgroup label="<?php _e('Network', 'podlove'); ?>"> |
||
0 ignored issues
–
show
|
|||
91 | <?php |
||
92 | foreach ($network_buttons as $subscribebutton) { |
||
0 ignored issues
–
show
|
|||
93 | echo "<option value='" . sanitize_title($subscribebutton->name) . "' " . selected( sanitize_title($subscribebutton->name), $button ) . " >" . sanitize_title($subscribebutton->title) . " (" . sanitize_title($subscribebutton->name) . ")</option>"; |
||
0 ignored issues
–
show
The string literal
> does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. ![]() The string literal
( does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. ![]() The string literal
)</option> does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. ![]() |
|||
94 | } |
||
95 | ?> |
||
96 | </optgroup> |
||
97 | <?php else : |
||
0 ignored issues
–
show
|
|||
98 | foreach ($buttons as $subscribebutton) { |
||
0 ignored issues
–
show
|
|||
99 | echo "<option value='" . sanitize_title($subscribebutton->name) . "' " . selected( sanitize_title($subscribebutton->name), $button ) . " >" . sanitize_title($subscribebutton->title) . " (" . sanitize_title($subscribebutton->name) . ")</option>"; |
||
0 ignored issues
–
show
The string literal
> does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. ![]() The string literal
( does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. ![]() The string literal
)</option> does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. ![]() |
|||
100 | } |
||
101 | endif; ?> |
||
0 ignored issues
–
show
|
|||
102 | </select> |
||
103 | |||
104 | <?php |
||
105 | $customize_options = array( |
||
106 | 'size' => array( |
||
107 | 'name' => __( 'Size', 'podlove-subscribe-button' ), |
||
108 | 'options' => \PodloveSubscribeButton\Model\Button::$size |
||
0 ignored issues
–
show
|
|||
109 | ), |
||
110 | 'style' => array( |
||
111 | 'name' => __( 'Style', 'podlove-subscribe-button' ), |
||
112 | 'options' => \PodloveSubscribeButton\Model\Button::$style |
||
0 ignored issues
–
show
|
|||
113 | ), |
||
114 | 'format' => array( |
||
115 | 'name' => __( 'Format', 'podlove-subscribe-button' ), |
||
116 | 'options' => \PodloveSubscribeButton\Model\Button::$format |
||
0 ignored issues
–
show
|
|||
117 | ), |
||
118 | 'autowidth' => array( |
||
119 | 'name' => __( 'Autowidth', 'podlove-subscribe-button' ), |
||
120 | 'options' => \PodloveSubscribeButton\Model\Button::$width |
||
0 ignored issues
–
show
|
|||
121 | ) |
||
0 ignored issues
–
show
|
|||
122 | ); |
||
123 | |||
124 | foreach ($customize_options as $slug => $properties) : ?> |
||
0 ignored issues
–
show
|
|||
125 | <label for="<?php echo $this->get_field_id( $slug ); ?>"><?php echo $properties['name']; ?></label> |
||
0 ignored issues
–
show
|
|||
126 | <select class="widefat" id="<?php echo $this->get_field_id( $slug ); ?>" name="<?php echo $this->get_field_name( $slug ); ?>"> |
||
0 ignored issues
–
show
|
|||
127 | <option value="default" <?php echo ( $$slug == 'default' ? 'selected="selected"' : '' ); ?>><?php printf( __( 'Default %s', 'podlove-subscribe-button' ), $properties['name'] ) ?></option> |
||
0 ignored issues
–
show
|
|||
128 | <optgroup> |
||
129 | <?php foreach ( $properties['options'] as $property => $name ) : ?> |
||
130 | <option value="<?php echo $property; ?>" <?php echo ( $$slug == $property ? 'selected="selected"' : '' ); ?>><?php echo $name; ?></option> |
||
0 ignored issues
–
show
|
|||
131 | <?php endforeach; ?> |
||
132 | </optgroup> |
||
133 | </select> |
||
134 | <?php endforeach; ?> |
||
135 | |||
136 | <label for="<?php echo $this->get_field_id( 'infotext' ); ?>"><?php _e( 'Description', 'podlove-subscribe-button' ); ?></label> |
||
0 ignored issues
–
show
|
|||
137 | <textarea class="widefat" rows="10" id="<?php echo $this->get_field_id( 'infotext' ); ?>" name="<?php echo $this->get_field_name( 'infotext' ); ?>"><?php echo $infotext; ?></textarea> |
||
0 ignored issues
–
show
|
|||
138 | </p> |
||
139 | <?php |
||
140 | } |
||
0 ignored issues
–
show
|
|||
141 | |||
142 | public function update( $new_instance, $old_instance ) { |
||
0 ignored issues
–
show
|
|||
143 | $instance = array(); |
||
144 | |||
145 | foreach (self::$widget_settings as $setting) { |
||
0 ignored issues
–
show
|
|||
146 | $instance[$setting] = ( ! empty( $new_instance[$setting] ) ) ? strip_tags( $new_instance[$setting] ) : ''; |
||
0 ignored issues
–
show
Equals sign not aligned correctly; expected 1 space but found 2 spaces
This check looks for improperly formatted assignments. Every assignment must have exactly one space before and one space after the equals operator. To illustrate: $a = "a";
$ab = "ab";
$abc = "abc";
will have no issues, while $a = "a";
$ab = "ab";
$abc = "abc";
will report issues in lines 1 and 2. ![]() |
|||
147 | } |
||
148 | |||
149 | return $instance; |
||
150 | } |
||
0 ignored issues
–
show
|
|||
151 | } |
||
152 | add_action( 'widgets_init', function(){ |
||
0 ignored issues
–
show
|
|||
153 | register_widget( '\PodloveSubscribeButton\Podlove_Subscribe_Button_Widget' ); |
||
0 ignored issues
–
show
|
|||
154 | }); |
||
0 ignored issues
–
show
For multi-line function calls, the closing parenthesis should be on a new line.
If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line: someFunctionCall(
$firstArgument,
$secondArgument,
$thirdArgument
); // Closing parenthesis on a new line.
![]() |
|||
155 |