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.

Issues (1495)

model/button.php (83 issues)

1
<?php
0 ignored issues
show
Class file names should be based on the class name with "class-" prepended. Expected class-button.php, but found button.php.
Loading history...
2
namespace PodloveSubscribeButton\Model;
3
4
class Button extends Base {
5
6
	public static $properties = array(
7
		// $property => $default value
8
		'size' => 'big',
0 ignored issues
show
Array double arrow not aligned correctly; expected 6 space(s) between "'size'" and double arrow, but found 1.
Loading history...
9
		'color' => '#599677',
0 ignored issues
show
Array double arrow not aligned correctly; expected 5 space(s) between "'color'" and double arrow, but found 1.
Loading history...
10
		'autowidth' => 'on',
11
		'style' => 'filled',
0 ignored issues
show
Array double arrow not aligned correctly; expected 5 space(s) between "'style'" and double arrow, but found 1.
Loading history...
12
		'format' => 'rectangle',
0 ignored issues
show
Array double arrow not aligned correctly; expected 4 space(s) between "'format'" and double arrow, but found 1.
Loading history...
13
		'hide' => 'false'
0 ignored issues
show
Array double arrow not aligned correctly; expected 6 space(s) between "'hide'" and double arrow, but found 1.
Loading history...
Each array item in a multi-line array declaration must end in a comma
Loading history...
14
		// Note: the fields 'language' and 'json-data' cannot be set here (No function call allowed within class variables)
15
	);
16
17
	public static $style = array(
18
		'filled' => 'Filled',
0 ignored issues
show
Array double arrow not aligned correctly; expected 4 space(s) between "'filled'" and double arrow, but found 1.
Loading history...
19
		'outline' => 'Outline',
0 ignored issues
show
Array double arrow not aligned correctly; expected 3 space(s) between "'outline'" and double arrow, but found 1.
Loading history...
20
		'frameless' => 'Frameless'
0 ignored issues
show
Each array item in a multi-line array declaration must end in a comma
Loading history...
21
	);
22
23
	public static $format = array(
24
		'rectangle' => 'Rectangle',
25
		'square' => 'Square',
0 ignored issues
show
Array double arrow not aligned correctly; expected 4 space(s) between "'square'" and double arrow, but found 1.
Loading history...
26
		'cover' => 'Cover'
0 ignored issues
show
Array double arrow not aligned correctly; expected 5 space(s) between "'cover'" and double arrow, but found 1.
Loading history...
Each array item in a multi-line array declaration must end in a comma
Loading history...
27
	);
28
29
	public static $width = array(
30
		'on' => 'Yes',
0 ignored issues
show
Array double arrow not aligned correctly; expected 2 space(s) between "'on'" and double arrow, but found 1.
Loading history...
31
		'off' => 'No'
0 ignored issues
show
Each array item in a multi-line array declaration must end in a comma
Loading history...
32
	);
33
34
	public static $size = array(
35
		'small' => 'Small',
0 ignored issues
show
Array double arrow not aligned correctly; expected 2 space(s) between "'small'" and double arrow, but found 1.
Loading history...
36
		'medium' => 'Medium',
37
		'big' => 'Big'
0 ignored issues
show
Array double arrow not aligned correctly; expected 4 space(s) between "'big'" and double arrow, but found 1.
Loading history...
Each array item in a multi-line array declaration must end in a comma
Loading history...
38
	);
39
40
41
	/**
42
	 * Fetches a Button or Network Button with a specific name
43
	 * @param  string $name
44
	 * @return object||FALSE
45
	 */
46
	public static function get_button_by_name($name) {
0 ignored issues
show
No space after opening parenthesis is prohibited
Loading history...
No space before closing parenthesis is prohibited
Loading history...
47
		if ( $button = \PodloveSubscribeButton\Model\Button::find_one_by_property('name', $name) ) {
0 ignored issues
show
Variable assignment found within a condition. Did you mean to do a comparison?
Loading history...
48
			return $button;
49
		}
50
51
		if ( $network_button = \PodloveSubscribeButton\Model\NetworkButton::find_one_by_property('name', $name) ) {
0 ignored issues
show
Variable assignment found within a condition. Did you mean to do a comparison?
Loading history...
52
			$network_button->id = $network_button->id . 'N';
53
			return $network_button;
54
		}
55
56
		return false;
57
	}
58
59
	/**
60
	 * Returns either global buttons settings or the default settings
61
	 * @param  array
62
	 * @return array
63
	 */
64
	public static function get_global_setting_with_fallback( $settings=array() ) {
65
		foreach (self::$properties as $property => $default) {
0 ignored issues
show
No space after opening parenthesis is prohibited
Loading history...
No space before closing parenthesis is prohibited
Loading history...
66
			$settings[$property] = ( get_option('podlove_subscribe_button_default_' . $property) ? get_option('podlove_subscribe_button_default_' . $property) : $default );
0 ignored issues
show
Array keys must be surrounded by spaces unless they contain a string or an integer.
Loading history...
67
		}
68
69
		return $settings;
70
	}
71
72
	/**
73
	 * Gathers all information and renders the Subscribe button.
74
	 * @param  string  $size
75
	 * @param  string  $autowidth
76
	 * @param  string  $style
77
	 * @param  string  $format
78
	 * @param  string  $color
79
	 * @param  boolean $hide
80
	 * @return string
81
	 */
82
	public function render( $size='big', $autowidth='on', $style='filled', $format='rectangle', $color='#599677', $hide = false, $buttonid = false, $language='en' ) {
83
		$button_styling = array_merge(
84
				$this->get_button_styling($size, $autowidth, $style, $format, $color),
85
				array(
86
						'hide' => $hide,
0 ignored issues
show
Array item not aligned correctly; expected 20 spaces but found 24
Loading history...
Array double arrow not aligned correctly; expected 5 space(s) between "'hide'" and double arrow, but found 1.
Loading history...
87
						'language' => $language
0 ignored issues
show
Array item not aligned correctly; expected 20 spaces but found 24
Loading history...
Each array item in a multi-line array declaration must end in a comma
Loading history...
88
					)
0 ignored issues
show
Array closer not aligned correctly; expected 16 space(s) but found 20
Loading history...
89
			);
90
91
		return $this->provide_button_html(
92
			array(
93
				'title' => sanitize_text_field($this->title),
0 ignored issues
show
Array double arrow not aligned correctly; expected 7 space(s) between "'title'" and double arrow, but found 1.
Loading history...
94
				'subtitle' => sanitize_text_field($this->subtitle),
0 ignored issues
show
Array double arrow not aligned correctly; expected 4 space(s) between "'subtitle'" and double arrow, but found 1.
Loading history...
95
				'description' => sanitize_textarea_field($this->description),
96
				'cover' => sanitize_text_field($this->cover),
0 ignored issues
show
Array double arrow not aligned correctly; expected 7 space(s) between "'cover'" and double arrow, but found 1.
Loading history...
97
				'feeds' => $this->get_feeds_as_array($this->feeds)
0 ignored issues
show
Array double arrow not aligned correctly; expected 7 space(s) between "'feeds'" and double arrow, but found 1.
Loading history...
Each array item in a multi-line array declaration must end in a comma
Loading history...
98
			), $button_styling );
99
	}
100
101
	/**
102
	 * Provides the feed as an array in the required format
103
	 * @return array
104
	 */
105
	private function get_feeds_as_array( $feeds=array() ) {
106
		$returnedFeeds = array();
0 ignored issues
show
Variable "returnedFeeds" is not in valid snake_case format
Loading history...
107
108
		if (! $feeds)
0 ignored issues
show
Expected 1 space before "!"; 0 found
Loading history...
109
			return $returnedFeeds;
0 ignored issues
show
Variable "returnedFeeds" is not in valid snake_case format
Loading history...
110
111
		foreach ($feeds as $feed) {
0 ignored issues
show
No space after opening parenthesis is prohibited
Loading history...
No space before closing parenthesis is prohibited
Loading history...
112
			if ( isset(\PodloveSubscribeButton\MediaTypes::$audio[$feed['format']]['extension']) ) {
0 ignored issues
show
Array keys must be surrounded by spaces unless they contain a string or an integer.
Loading history...
113
				$new_feed = array(
114
						'type' => 'audio',
0 ignored issues
show
Array item not aligned correctly; expected 20 spaces but found 24
Loading history...
Array double arrow not aligned correctly; expected 4 space(s) between "'type'" and double arrow, but found 1.
Loading history...
115
						'format' => \PodloveSubscribeButton\MediaTypes::$audio[$feed['format']]['extension'],
0 ignored issues
show
Array item not aligned correctly; expected 20 spaces but found 24
Loading history...
Array double arrow not aligned correctly; expected 2 space(s) between "'format'" and double arrow, but found 1.
Loading history...
Array keys must be surrounded by spaces unless they contain a string or an integer.
Loading history...
116
						'url' => $feed['url'],
0 ignored issues
show
Array item not aligned correctly; expected 20 spaces but found 24
Loading history...
Array double arrow not aligned correctly; expected 5 space(s) between "'url'" and double arrow, but found 1.
Loading history...
117
						'variant' => 'high'
0 ignored issues
show
Array item not aligned correctly; expected 20 spaces but found 24
Loading history...
Each array item in a multi-line array declaration must end in a comma
Loading history...
118
					);
0 ignored issues
show
Array closer not aligned correctly; expected 16 space(s) but found 20
Loading history...
119
120
				if ( isset($feed['itunesfeedid']) && $feed['itunesfeedid'] > 0 )
121
					$new_feed['directory-url-itunes'] = "https://itunes.apple.com/podcast/id" . $feed['itunesfeedid'];
122
123
				$returnedFeeds[] = $new_feed;
0 ignored issues
show
Variable "returnedFeeds" is not in valid snake_case format
Loading history...
124
			}
125
		}
126
127
		return $returnedFeeds;
0 ignored issues
show
Variable "returnedFeeds" is not in valid snake_case format
Loading history...
128
	}
129
130
	/**
131
	 * Provides the HTML source of the Subscribe Button
132
	 * @param  array $podcast_data
133
	 * @param  array $button_styling
134
	 * @param  string $data_attributes
135
	 * @return string
136
	 */
137
	private function provide_button_html($podcast_data, $button_styling, $data_attributes="") {
0 ignored issues
show
No space after opening parenthesis is prohibited
Loading history...
No space before closing parenthesis is prohibited
Loading history...
138
		// Create data attributes for Button
139
		foreach ($button_styling as $attribute => $value) {
0 ignored issues
show
No space after opening parenthesis is prohibited
Loading history...
No space before closing parenthesis is prohibited
Loading history...
140
			$data_attributes .= 'data-' . $attribute . '="' . $value . '" ';
141
		}
142
143
		return"
144
			<script>
145
				podcastData".$this->id . " = ".json_encode($podcast_data)."
0 ignored issues
show
json_encode() is discouraged. Use wp_json_encode() instead.
Loading history...
146
			</script>
147
			<script
148
				class=\"podlove-subscribe-button\"
149
				src=\"https://cdn.podlove.org/subscribe-button/javascripts/app.js\" " . $data_attributes . ">
150
			</script>
151
		";
152
	}
153
154
	/**
155
	 * Returns an array with either the set or default values
156
	 * @param  string $size
157
	 * @param  string $autowidth
158
	 * @param  string $style
159
	 * @param  string $format
160
	 * @param  string $color
161
	 * @return array
162
	 */
163
	public function get_button_styling($size, $autowidth, $style, $format, $color) {
0 ignored issues
show
No space after opening parenthesis is prohibited
Loading history...
No space before closing parenthesis is prohibited
Loading history...
164
165
		return array(
166
				// $attribute => $value
0 ignored issues
show
Array item not aligned correctly; expected 12 spaces but found 16
Loading history...
167
				'size' => ( $size == 'default' ? get_option('podlove_subscribe_button_default_size', $size) : $size )
0 ignored issues
show
Multi-line array item not aligned correctly; expected 12 spaces, but found 16
Loading history...
Array double arrow not aligned correctly; expected 6 space(s) between "'size'" and double arrow, but found 1.
Loading history...
Found: ==. Use strict comparisons (=== or !==).
Loading history...
Use Yoda Condition checks, you must.
Loading history...
168
			 	. self::interpret_autowidth_attribute($autowidth),
169
				'style' => ( $style == 'default' ? get_option('podlove_subscribe_button_default_style', $style) : $style ),
0 ignored issues
show
Array item not aligned correctly; expected 12 spaces but found 16
Loading history...
Array double arrow not aligned correctly; expected 5 space(s) between "'style'" and double arrow, but found 1.
Loading history...
Found: ==. Use strict comparisons (=== or !==).
Loading history...
Use Yoda Condition checks, you must.
Loading history...
170
				'format' => ( $format == 'default' ? get_option('podlove_subscribe_button_default_format', $format) : $format ),
0 ignored issues
show
Array item not aligned correctly; expected 12 spaces but found 16
Loading history...
Array double arrow not aligned correctly; expected 4 space(s) between "'format'" and double arrow, but found 1.
Loading history...
Found: ==. Use strict comparisons (=== or !==).
Loading history...
Use Yoda Condition checks, you must.
Loading history...
171
				'color' => ( isset($color) ? $color : get_option('podlove_subscribe_button_default_color', $color) ),
0 ignored issues
show
Array item not aligned correctly; expected 12 spaces but found 16
Loading history...
Array double arrow not aligned correctly; expected 5 space(s) between "'color'" and double arrow, but found 1.
Loading history...
172
				'json-data' => 'podcastData' . $this->id
0 ignored issues
show
Array item not aligned correctly; expected 12 spaces but found 16
Loading history...
Each array item in a multi-line array declaration must end in a comma
Loading history...
173
			);
0 ignored issues
show
Array closer not aligned correctly; expected 8 space(s) but found 12
Loading history...
174
	}
175
176
	/**
177
	 * Helper function to interpret the given $autowidth value correctly
178
	 * @param  string $autowidth
179
	 * @return string
180
	 */
181
	private static function interpret_autowidth_attribute($autowidth) {
0 ignored issues
show
No space after opening parenthesis is prohibited
Loading history...
No space before closing parenthesis is prohibited
Loading history...
182
		if ( $autowidth == 'default' && get_option('podlove_subscribe_button_default_autowidth') !== 'on' )
0 ignored issues
show
Found: ==. Use strict comparisons (=== or !==).
Loading history...
Use Yoda Condition checks, you must.
Loading history...
183
			return '';
184
185
		if ( $autowidth !== 'default' && $autowidth !== 'on' )
0 ignored issues
show
Use Yoda Condition checks, you must.
Loading history...
186
			return '';
187
188
		return ' auto';
189
	}
190
}
191
192
Button::property( 'id', 'INT NOT NULL AUTO_INCREMENT PRIMARY KEY' );
193
Button::property( 'name', 'VARCHAR(255)' );
194
Button::property( 'title', 'VARCHAR(255)' );
195
Button::property( 'subtitle', 'VARCHAR(255)' );
196
Button::property( 'description', 'TEXT' );
197
Button::property( 'cover', 'VARCHAR(255)' );
198
Button::property( 'feeds', 'TEXT' );
199