GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Pull Request — master (#42)
by Christian
02:49
created

podlove.php (74 issues)

1
<?php
0 ignored issues
show
Class file names should be based on the class name with "class-" prepended. Expected class-podlovesubscribebutton.php, but found podlove.php.
Loading history...
2
/**
0 ignored issues
show
Missing short description in doc comment
Loading history...
3
 * @author    Podlove <[email protected]>
4
 * @copyright Copyright (c) 2014-2018, Podlove
5
 * @license   https://github.com/podlove/podlove-subscribe-button-wp-plugin/blob/master/LICENSE MIT
6
 * @package   Podlove\PodloveSubscribeButton
7
 * @version   1.4.0-beta
8
 */
9
10
/**
11
 * Plugin Name: Podlove Subscribe Button
12
 * Plugin URI:  https://wordpress.org/plugins/podlove-subscribe-button/
13
 * Description: Brings the Podlove Subscribe Button to your WordPress installation.
14
 * Version:     1.4.0-beta
15
 * Author:      Podlove
16
 * Author URI:  https://podlove.org/
17
 * License:     MIT
18
 * License URI: license.txt
19
 * Text Domain: podlove-subscribe-button
20
 */
21
22
/** Check if PHP version is sufficient */
23
if ( ! version_compare( phpversion(), '5.3', ">=" ) ) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
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 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

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 (\') and the backslash (\\). Every other character is displayed as is.

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: Single is Value

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.

Loading history...
24
25
	require_once 'php-version.php';
26
	add_action( 'admin_notices', 'podlove_psb_php_notice' );
27
	add_action( 'admin_init', function() {
0 ignored issues
show
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
For multi-line function calls, each argument should be on a separate line.

For a function calls that spawns multiple lines, the coding style suggests to split arguments to separate lines like this:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
);
Loading history...
28
		deactivate_plugins( plugin_basename( __FILE__ ) );
29
	} );
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.
Loading history...
30
	return;
31
32
}
33
34
require_once __DIR__ . '/vendor/autoload.php';
35
36
// Constants
0 ignored issues
show
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
37
require( 'constants.php' );
0 ignored issues
show
"require" is a statement not a function; no parentheses are required
Loading history...
38
// Media Types
0 ignored issues
show
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
39
require( 'media_types.php' );
0 ignored issues
show
"require" is a statement not a function; no parentheses are required
Loading history...
40
// Version control
0 ignored issues
show
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
41
require( 'version.php' );
0 ignored issues
show
"require" is a statement not a function; no parentheses are required
Loading history...
42
// Helper functions
0 ignored issues
show
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
43
require( 'helper.php' );
0 ignored issues
show
"require" is a statement not a function; no parentheses are required
Loading history...
44
45
register_activation_hook( __FILE__, array( 'PodloveSubscribeButton', 'build_models' ) );
46
47
PodloveSubscribeButton::run();
48
49
/**
50
 * Class PodloveSubscribeButton
51
 */
52
class PodloveSubscribeButton {
53
54
	/**
0 ignored issues
show
Missing short description in doc comment
Loading history...
55
	 * @var string current plugin version
56
	 */
57
	public static $version = '1.4.0-beta';
58
59
	public static function run() {
0 ignored issues
show
Coding Style Documentation introduced by
Missing doc comment for function run()
Loading history...
60
		add_action( 'plugins_loaded', array( __CLASS__, 'load_translations' ) );
61
		add_action( 'init', array( __CLASS__, 'register_shortcode' ) );
62
		add_action( 'admin_init', array( __CLASS__, 'register_settings' ) );
63
		add_action( 'admin_init', array( 'PodloveSubscribeButton\Settings\Buttons', 'process_form' ) );
64
		add_action( 'admin_enqueue_scripts', array( __CLASS__, 'enqueue_assets' ) );
65
		add_action( 'widgets_init', array( __CLASS__, 'widgets' ) );
66
		self::menu();
67
68
	}
69
70
	public static function widgets() {
0 ignored issues
show
Coding Style Documentation introduced by
Missing doc comment for function widgets()
Loading history...
71
		register_widget( '\PodloveSubscribeButton\Widget' );
72
73
	}
74
75
	public static function menu() {
0 ignored issues
show
Coding Style Documentation introduced by
Missing doc comment for function menu()
Loading history...
76
		add_action( 'admin_menu', array( 'PodloveSubscribeButton', 'admin_menu' ) );
77
78
		if ( is_network_admin() ) {
79
			add_action( 'network_admin_menu', array( 'PodloveSubscribeButton', 'admin_network_menu' ) );
80
		}
81
82
	}
83
84
	public static function enqueue_assets( $hook ) {
0 ignored issues
show
Method name "PodloveSubscribeButton::enqueue_assets" is not in camel caps format
Loading history...
Coding Style Documentation introduced by
Missing doc comment for function enqueue_assets()
Loading history...
85
86
		$pages = array( 'settings_page_podlove-subscribe-button', 'widgets.php' );
87
88
		if ( ! in_array( $hook, $pages ) ) {
0 ignored issues
show
Not using strict comparison for in_array; supply true for third argument.
Loading history...
89
			return;
90
		}
91
92
		// CSS Stylesheet
0 ignored issues
show
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
93
		wp_register_style( 'podlove-subscribe-button', plugin_dir_url( __FILE__ ) . 'style.css', false, self::$version );
0 ignored issues
show
false of type false is incompatible with the type array expected by parameter $deps of wp_register_style(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

93
		wp_register_style( 'podlove-subscribe-button', plugin_dir_url( __FILE__ ) . 'style.css', /** @scrutinizer ignore-type */ false, self::$version );
Loading history...
94
		wp_enqueue_style( 'podlove-subscribe-button' );
95
96
		// Admin JS
0 ignored issues
show
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
97
		wp_enqueue_style( 'wp-color-picker' );
98
		wp_register_script( 'podlove-subscribe-button-admin-tools', plugin_dir_url( __FILE__ ) . 'js/admin.js', array( 'jquery', 'wp-color-picker' ), self::$version );
0 ignored issues
show
In footer ($in_footer) is not set explicitly wp_register_script; It is recommended to load scripts in the footer. Please set this value to true to load it in the footer, or explicitly false if it should be loaded in the header.
Loading history...
99
		$js_translations = array(
100
			'media_library' => __( 'Media Library', 'podlove-subscribe-button' ),
101
			'use_for'       => __( 'Use for Podcast Cover Art', 'podlove-subscribe-button' ),
102
		);
103
		wp_localize_script( 'podlove-subscribe-button-admin-tools', 'i18n', $js_translations );
104
		wp_enqueue_script( 'podlove-subscribe-button-admin-tools' );
105
106
	}
107
108
	public static function admin_menu() {
0 ignored issues
show
Method name "PodloveSubscribeButton::admin_menu" is not in camel caps format
Loading history...
Coding Style Documentation introduced by
Missing doc comment for function admin_menu()
Loading history...
109
		add_options_page(
110
			__( 'Podlove Subscribe Button Options', 'podlove-subscribe-button' ),
111
			__( 'Podlove Subscribe Button', 'podlove-subscribe-button' ),
112
			'manage_options',
113
			'podlove-subscribe-button',
114
			array( 'PodloveSubscribeButton\Settings\Buttons', 'page' )
115
		);
116
117
	}
118
119
	public static function admin_network_menu() {
0 ignored issues
show
Method name "PodloveSubscribeButton::admin_network_menu" is not in camel caps format
Loading history...
Coding Style Documentation introduced by
Missing doc comment for function admin_network_menu()
Loading history...
120
		add_submenu_page(
121
			'settings.php',
122
			__( 'Podlove Subscribe Button Options', 'podlove-subscribe-button' ),
123
			__( 'Podlove Subscribe Button', 'podlove-subscribe-button' ),
124
			'manage_options',
125
			'podlove-subscribe-button',
126
			array( 'PodloveSubscribeButton\Settings\Buttons', 'page' )
127
		);
128
129
	}
130
131
	public static function load_translations() {
0 ignored issues
show
Method name "PodloveSubscribeButton::load_translations" is not in camel caps format
Loading history...
Coding Style Documentation introduced by
Missing doc comment for function load_translations()
Loading history...
132
		load_plugin_textdomain( 'podlove-subscribe-button' );
133
134
	}
135
136
	public static function register_settings() {
0 ignored issues
show
Method name "PodloveSubscribeButton::register_settings" is not in camel caps format
Loading history...
Coding Style Documentation introduced by
Missing doc comment for function register_settings()
Loading history...
137
		$settings = array(
138
			'size',
139
			'autowidth',
140
			'style',
141
			'format',
142
			'color',
143
		);
144
145
		foreach ( $settings as $setting ) {
146
			register_setting( 'podlove-subscribe-button', 'podlove_subscribe_button_default_' . $setting );
147
		}
148
149
	}
150
151
	public static function register_shortcode() {
0 ignored issues
show
Method name "PodloveSubscribeButton::register_shortcode" is not in camel caps format
Loading history...
Coding Style Documentation introduced by
Missing doc comment for function register_shortcode()
Loading history...
152
		add_shortcode( 'podlove-subscribe-button', array( 'PodloveSubscribeButton', 'shortcode' ) );
153
154
	}
155
156
	public static function build_models() {
0 ignored issues
show
Method name "PodloveSubscribeButton::build_models" is not in camel caps format
Loading history...
Coding Style Documentation introduced by
Missing doc comment for function build_models()
Loading history...
157
		// Build Databases
0 ignored issues
show
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
158
		\PodloveSubscribeButton\Model\Button::build();
159
160
		if ( is_multisite() ) {
161
			\PodloveSubscribeButton\Model\NetworkButton::build();
162
		}
163
164
		// Set Button "default" values
0 ignored issues
show
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
165
		$default_values = array(
166
			'size'      => 'big',
167
			'autowidth' => 'on',
168
			'color'     => '#599677',
169
			'style'     => 'filled',
170
			'format'    => 'rectangle'
0 ignored issues
show
Each array item in a multi-line array declaration must end in a comma
Loading history...
171
		);
172
173
		foreach ( $default_values as $option => $default_value ) {
174
			if ( ! get_option( 'podlove_subscribe_button_default_' . $option ) ) {
175
				update_option( 'podlove_subscribe_button_default_' . $option, $default_value );
176
			}
177
		}
178
179
	}
180
181
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$args" missing
Loading history...
182
	 * Add the shortcode
183
	 *
184
	 * @param $args
0 ignored issues
show
Missing parameter name
Loading history...
185
	 *
186
	 * @return string|void
187
	 */
188
	public static function shortcode( $args ) {
189
		if ( ! $args || ! isset( $args[ 'button' ] ) ) {
0 ignored issues
show
Array keys must NOT be surrounded by spaces if they only contain a string or an integer.
Loading history...
190
			return __( 'You need to create a Button first and provide its ID.', 'podlove-subscribe-button' );
191
		} else {
192
			$buttonid = $args[ 'button' ];
0 ignored issues
show
Array keys must NOT be surrounded by spaces if they only contain a string or an integer.
Loading history...
193
		}
194
195
		// Fetch the (network)button by it's name
0 ignored issues
show
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
196
		if ( ! $button = \PodloveSubscribeButton\Model\Button::get_button_by_name( $args[ 'button' ] ) )
0 ignored issues
show
Coding Style Best Practice introduced by
It is generally a best practice to always use braces with control structures.

Adding braces to control structures avoids accidental mistakes as your code changes:

// Without braces (not recommended)
if (true)
    doSomething();

// Recommended
if (true) {
    doSomething();
}
Loading history...
Variable assignment found within a condition. Did you mean to do a comparison?
Loading history...
Assignments must be the first block of code on a line
Loading history...
Array keys must NOT be surrounded by spaces if they only contain a string or an integer.
Loading history...
197
			return sprintf( __( 'Oops. There is no button with the ID "%s".', 'podlove-subscribe-button' ), $args[ 'button' ] );
0 ignored issues
show
A gettext call containing placeholders was found, but was not accompanied by a "translators:" comment on the line above to clarify the meaning of the placeholders.
Loading history...
Array keys must NOT be surrounded by spaces if they only contain a string or an integer.
Loading history...
198
199
		// Get button styling and options
0 ignored issues
show
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
200
		$autowidth = self::interpret_width_attribute( self::get_array_value_with_fallback( $args, 'width' ) );
0 ignored issues
show
It seems like self::get_array_value_wi...allback($args, 'width') can also be of type false; however, parameter $width_attribute of PodloveSubscribeButton::...rpret_width_attribute() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

200
		$autowidth = self::interpret_width_attribute( /** @scrutinizer ignore-type */ self::get_array_value_with_fallback( $args, 'width' ) );
Loading history...
201
		$size      = self::get_attribute( 'size', self::get_array_value_with_fallback( $args, 'size' ) );
0 ignored issues
show
It seems like self::get_array_value_wi...fallback($args, 'size') can also be of type false; however, parameter $attribute_value of PodloveSubscribeButton::get_attribute() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

201
		$size      = self::get_attribute( 'size', /** @scrutinizer ignore-type */ self::get_array_value_with_fallback( $args, 'size' ) );
Loading history...
202
		$style     = self::get_attribute( 'style', self::get_array_value_with_fallback( $args, 'style' ) );
203
		$format    = self::get_attribute( 'format', self::get_array_value_with_fallback( $args, 'format' ) );
204
		$color     = self::get_attribute( 'color', self::get_array_value_with_fallback( $args, 'color' ) );
0 ignored issues
show
The assignment to $color is dead and can be removed.
Loading history...
205
206
		if ( isset( $args[ 'language' ] ) ) {
0 ignored issues
show
Array keys must NOT be surrounded by spaces if they only contain a string or an integer.
Loading history...
207
			$language = $args[ 'language' ];
0 ignored issues
show
Array keys must NOT be surrounded by spaces if they only contain a string or an integer.
Loading history...
208
		} else {
209
			$language = 'en';
210
		}
211
212
		if ( isset( $args[ 'color' ] ) ) {
0 ignored issues
show
Array keys must NOT be surrounded by spaces if they only contain a string or an integer.
Loading history...
213
			$color = $args[ 'color' ];
0 ignored issues
show
Array keys must NOT be surrounded by spaces if they only contain a string or an integer.
Loading history...
214
		} else {
215
			$color = get_option( 'podlove_subscribe_button_default_color', '#599677' );
216
		}
217
218
		if ( isset( $args[ 'hide' ] ) && $args[ 'hide' ] == 'true' ) {
0 ignored issues
show
Array keys must NOT be surrounded by spaces if they only contain a string or an integer.
Loading history...
Found: ==. Use strict comparisons (=== or !==).
Loading history...
Use Yoda Condition checks, you must.
Loading history...
219
			$hide = true;
220
		} else {
221
			$hide = false;
222
		}
223
224
		// Render button
0 ignored issues
show
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
225
		return $button->render( $size, $autowidth, $style, $format, $color, $hide, $buttonid, $language );
226
227
	}
228
229
	public static function get_array_value_with_fallback( $args, $key ) {
0 ignored issues
show
Method name "PodloveSubscribeButton::get_array_value_with_fallback" is not in camel caps format
Loading history...
Coding Style Documentation introduced by
Missing doc comment for function get_array_value_with_fallback()
Loading history...
230
		if ( isset( $args[ $key ] ) ) {
231
			return $args[ $key ];
232
		}
233
234
		return false;
235
236
	}
237
238
	/**
0 ignored issues
show
Missing short description in doc comment
Loading history...
239
	 * @param  string $attribute
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
240
	 * @param  string $attribute_value
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
241
	 * @return string
242
	 */
243
	private static function get_attribute( $attribute = null, $attribute_value = null ) {
0 ignored issues
show
Method name "PodloveSubscribeButton::get_attribute" is not in camel caps format
Loading history...
244
		if ( isset( $attribute_value ) && ctype_alnum( $attribute_value ) && key_exists( $attribute_value, \PodloveSubscribeButton\Model\Button::$$attribute ) ) {
245
			return $attribute_value;
246
		} else {
247
			return get_option( 'podlove_subscribe_button_default_' . $attribute, \PodloveSubscribeButton\Model\Button::$properties[ $attribute ] );
248
		}
249
250
	}
251
252
	/**
253
	 * Interprets the provided width attribute and return either auto- or a specific width
254
	 *
255
	 * @param  string $width_attribute
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
256
	 * @return string
257
	 */
258
	private static function interpret_width_attribute( $width_attribute = null ) {
0 ignored issues
show
Method name "PodloveSubscribeButton::interpret_width_attribute" is not in camel caps format
Loading history...
259
		if ( $width_attribute == 'auto' ) {
0 ignored issues
show
Found: ==. Use strict comparisons (=== or !==).
Loading history...
Use Yoda Condition checks, you must.
Loading history...
260
			return 'on';
261
		}
262
263
		if ( $width_attribute && $width_attribute !== 'auto' ) {
0 ignored issues
show
Use Yoda Condition checks, you must.
Loading history...
264
			return 'off';
265
		}
266
267
		return get_option( 'podlove_subscribe_button_default_autowidth', 'on' );
268
269
	}
270
271
} // END class
272