Conditions | 3 |
Paths | 3 |
Total Lines | 11 |
Code Lines | 6 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Metric | Value |
---|---|
cc | 3 |
eloc | 6 |
nc | 3 |
nop | 1 |
dl | 0 |
loc | 11 |
rs | 10 |
c | 0 |
b | 0 |
f | 0 |
1 | <?php |
||||
0 ignored issues
–
show
introduced
by
![]() |
|||||
2 | namespace PodloveSubscribeButton\Model; |
||||
3 | |||||
4 | class Button extends Base { |
||||
0 ignored issues
–
show
|
|||||
5 | |||||
6 | public static $properties = array( |
||||
0 ignored issues
–
show
|
|||||
7 | // $property => $default value |
||||
0 ignored issues
–
show
43% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||||
8 | 'size' => 'big', |
||||
0 ignored issues
–
show
|
|||||
9 | 'color' => '#599677', |
||||
0 ignored issues
–
show
|
|||||
10 | 'autowidth' => 'on', |
||||
11 | 'style' => 'filled', |
||||
0 ignored issues
–
show
|
|||||
12 | 'format' => 'rectangle', |
||||
0 ignored issues
–
show
|
|||||
13 | 'hide' => 'false' |
||||
0 ignored issues
–
show
|
|||||
14 | // Note: the fields 'language' and 'json-data' cannot be set here (No function call allowed within class variables) |
||||
0 ignored issues
–
show
|
|||||
15 | ); |
||||
16 | |||||
17 | public static $style = array( |
||||
0 ignored issues
–
show
|
|||||
18 | 'filled' => 'Filled', |
||||
0 ignored issues
–
show
|
|||||
19 | 'outline' => 'Outline', |
||||
0 ignored issues
–
show
|
|||||
20 | 'frameless' => 'Frameless' |
||||
0 ignored issues
–
show
|
|||||
21 | ); |
||||
22 | |||||
23 | public static $format = array( |
||||
0 ignored issues
–
show
|
|||||
24 | 'rectangle' => 'Rectangle', |
||||
25 | 'square' => 'Square', |
||||
0 ignored issues
–
show
|
|||||
26 | 'cover' => 'Cover' |
||||
0 ignored issues
–
show
|
|||||
27 | ); |
||||
28 | |||||
29 | public static $width = array( |
||||
0 ignored issues
–
show
|
|||||
30 | 'on' => 'Yes', |
||||
0 ignored issues
–
show
|
|||||
31 | 'off' => 'No' |
||||
0 ignored issues
–
show
|
|||||
32 | ); |
||||
33 | |||||
34 | public static $size = array( |
||||
0 ignored issues
–
show
|
|||||
35 | 'small' => 'Small', |
||||
0 ignored issues
–
show
|
|||||
36 | 'medium' => 'Medium', |
||||
37 | 'big' => 'Big' |
||||
0 ignored issues
–
show
|
|||||
38 | ); |
||||
39 | |||||
40 | |||||
41 | /** |
||||
42 | * Fetches a Button or Network Button with a specific name |
||||
43 | * @param string $name |
||||
0 ignored issues
–
show
|
|||||
44 | * @return object||FALSE |
||||
0 ignored issues
–
show
|
|||||
45 | */ |
||||
46 | public static function get_button_by_name($name) { |
||||
0 ignored issues
–
show
|
|||||
47 | if ( $button = \PodloveSubscribeButton\Model\Button::find_one_by_property('name', $name) ) { |
||||
0 ignored issues
–
show
As per coding style,
self should be used for accessing local static members.
This check looks for accesses to local static members using the fully qualified name instead
of <?php
class Certificate {
const TRIPLEDES_CBC = 'ASDFGHJKL';
private $key;
public function __construct()
{
$this->key = Certificate::TRIPLEDES_CBC;
}
}
While this is perfectly valid, the fully qualified name of ![]() |
|||||
48 | return $button; |
||||
49 | } |
||||
50 | |||||
51 | if ( $network_button = \PodloveSubscribeButton\Model\NetworkButton::find_one_by_property('name', $name) ) { |
||||
0 ignored issues
–
show
|
|||||
52 | $network_button->id = $network_button->id . 'N'; |
||||
53 | return $network_button; |
||||
54 | } |
||||
55 | |||||
56 | return false; |
||||
57 | } |
||||
0 ignored issues
–
show
|
|||||
58 | |||||
59 | /** |
||||
0 ignored issues
–
show
|
|||||
60 | * Returns either global buttons settings or the default settings |
||||
61 | * @param array |
||||
0 ignored issues
–
show
|
|||||
62 | * @return array |
||||
63 | */ |
||||
64 | public static function get_global_setting_with_fallback( $settings=array() ) { |
||||
0 ignored issues
–
show
|
|||||
65 | foreach (self::$properties as $property => $default) { |
||||
0 ignored issues
–
show
|
|||||
66 | $settings[$property] = ( get_option('podlove_subscribe_button_default_' . $property) ? get_option('podlove_subscribe_button_default_' . $property) : $default ); |
||||
0 ignored issues
–
show
|
|||||
67 | } |
||||
68 | |||||
69 | return $settings; |
||||
70 | } |
||||
0 ignored issues
–
show
|
|||||
71 | |||||
72 | /** |
||||
0 ignored issues
–
show
|
|||||
73 | * Gathers all information and renders the Subscribe button. |
||||
74 | * @param string $size |
||||
0 ignored issues
–
show
|
|||||
75 | * @param string $autowidth |
||||
0 ignored issues
–
show
|
|||||
76 | * @param string $style |
||||
0 ignored issues
–
show
|
|||||
77 | * @param string $format |
||||
0 ignored issues
–
show
|
|||||
78 | * @param string $color |
||||
0 ignored issues
–
show
|
|||||
79 | * @param boolean $hide |
||||
0 ignored issues
–
show
|
|||||
80 | * @return string |
||||
81 | */ |
||||
82 | public function render( $size='big', $autowidth='on', $style='filled', $format='rectangle', $color='#599677', $hide = false, $buttonid = false, $language='en' ) { |
||||
0 ignored issues
–
show
|
|||||
83 | $button_styling = array_merge( |
||||
84 | $this->get_button_styling($size, $autowidth, $style, $format, $color), |
||||
0 ignored issues
–
show
|
|||||
85 | array( |
||||
0 ignored issues
–
show
|
|||||
86 | 'hide' => $hide, |
||||
0 ignored issues
–
show
|
|||||
87 | 'language' => $language |
||||
0 ignored issues
–
show
|
|||||
88 | ) |
||||
0 ignored issues
–
show
|
|||||
89 | ); |
||||
0 ignored issues
–
show
|
|||||
90 | |||||
91 | return $this->provide_button_html( |
||||
92 | array( |
||||
93 | 'title' => sanitize_text_field($this->title), |
||||
0 ignored issues
–
show
The property
title does not exist on PodloveSubscribeButton\Model\Button . Since you implemented __get , consider adding a @property annotation.
![]() |
|||||
94 | 'subtitle' => sanitize_text_field($this->subtitle), |
||||
0 ignored issues
–
show
The property
subtitle does not exist on PodloveSubscribeButton\Model\Button . Since you implemented __get , consider adding a @property annotation.
![]() |
|||||
95 | 'description' => sanitize_textarea_field($this->description), |
||||
0 ignored issues
–
show
The property
description does not exist on PodloveSubscribeButton\Model\Button . Since you implemented __get , consider adding a @property annotation.
![]() |
|||||
96 | 'cover' => sanitize_text_field($this->cover), |
||||
0 ignored issues
–
show
The property
cover does not exist on PodloveSubscribeButton\Model\Button . Since you implemented __get , consider adding a @property annotation.
![]() |
|||||
97 | 'feeds' => $this->get_feeds_as_array($this->feeds) |
||||
0 ignored issues
–
show
The property
feeds does not exist on PodloveSubscribeButton\Model\Button . Since you implemented __get , consider adding a @property annotation.
![]() |
|||||
98 | ), $button_styling ); |
||||
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.
![]() |
|||||
99 | } |
||||
0 ignored issues
–
show
|
|||||
100 | |||||
101 | /** |
||||
0 ignored issues
–
show
|
|||||
102 | * Provides the feed as an array in the required format |
||||
103 | * @return array |
||||
0 ignored issues
–
show
|
|||||
104 | */ |
||||
105 | private function get_feeds_as_array( $feeds=array() ) { |
||||
0 ignored issues
–
show
|
|||||
106 | $returnedFeeds = array(); |
||||
0 ignored issues
–
show
|
|||||
107 | |||||
108 | if (! $feeds) |
||||
0 ignored issues
–
show
|
|||||
109 | return $returnedFeeds; |
||||
0 ignored issues
–
show
|
|||||
110 | |||||
111 | foreach ($feeds as $feed) { |
||||
0 ignored issues
–
show
|
|||||
112 | if ( isset(\PodloveSubscribeButton\MediaTypes::$audio[$feed['format']]['extension']) ) { |
||||
0 ignored issues
–
show
|
|||||
113 | $new_feed = array( |
||||
114 | 'type' => 'audio', |
||||
0 ignored issues
–
show
|
|||||
115 | 'format' => \PodloveSubscribeButton\MediaTypes::$audio[$feed['format']]['extension'], |
||||
0 ignored issues
–
show
|
|||||
116 | 'url' => $feed['url'], |
||||
0 ignored issues
–
show
|
|||||
117 | 'variant' => 'high' |
||||
0 ignored issues
–
show
|
|||||
118 | ); |
||||
0 ignored issues
–
show
|
|||||
119 | |||||
120 | if ( isset($feed['itunesfeedid']) && $feed['itunesfeedid'] > 0 ) |
||||
0 ignored issues
–
show
|
|||||
121 | $new_feed['directory-url-itunes'] = "https://itunes.apple.com/podcast/id" . $feed['itunesfeedid']; |
||||
0 ignored issues
–
show
The string literal
https://itunes.apple.com/podcast/id 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. ![]() |
|||||
122 | |||||
123 | $returnedFeeds[] = $new_feed; |
||||
0 ignored issues
–
show
|
|||||
124 | } |
||||
125 | } |
||||
126 | |||||
127 | return $returnedFeeds; |
||||
0 ignored issues
–
show
|
|||||
128 | } |
||||
0 ignored issues
–
show
|
|||||
129 | |||||
130 | /** |
||||
131 | * Provides the HTML source of the Subscribe Button |
||||
132 | * @param array $podcast_data |
||||
0 ignored issues
–
show
|
|||||
133 | * @param array $button_styling |
||||
0 ignored issues
–
show
|
|||||
134 | * @param string $data_attributes |
||||
0 ignored issues
–
show
|
|||||
135 | * @return string |
||||
136 | */ |
||||
137 | private function provide_button_html($podcast_data, $button_styling, $data_attributes="") { |
||||
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. ![]() |
|||||
138 | // Create data attributes for Button |
||||
0 ignored issues
–
show
|
|||||
139 | foreach ($button_styling as $attribute => $value) { |
||||
0 ignored issues
–
show
|
|||||
140 | $data_attributes .= 'data-' . $attribute . '="' . $value . '" '; |
||||
141 | } |
||||
142 | |||||
143 | return" |
||||
0 ignored issues
–
show
The string literal
\n <script>\n podcastData 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. ![]() |
|||||
144 | <script> |
||||
145 | podcastData".$this->id . " = ".json_encode($podcast_data)." |
||||
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
\n </script>\n <scri...n/javascripts/app.js\" 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. ![]() |
|||||
146 | </script> |
||||
147 | <script |
||||
148 | class=\"podlove-subscribe-button\" |
||||
149 | src=\"https://cdn.podlove.org/subscribe-button/javascripts/app.js\" " . $data_attributes . "> |
||||
0 ignored issues
–
show
The string literal
>\n </script>\n 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. ![]() |
|||||
150 | </script> |
||||
151 | "; |
||||
152 | } |
||||
0 ignored issues
–
show
|
|||||
153 | |||||
154 | /** |
||||
155 | * Returns an array with either the set or default values |
||||
156 | * @param string $size |
||||
0 ignored issues
–
show
|
|||||
157 | * @param string $autowidth |
||||
0 ignored issues
–
show
|
|||||
158 | * @param string $style |
||||
0 ignored issues
–
show
|
|||||
159 | * @param string $format |
||||
0 ignored issues
–
show
|
|||||
160 | * @param string $color |
||||
0 ignored issues
–
show
|
|||||
161 | * @return array |
||||
162 | */ |
||||
163 | public function get_button_styling($size, $autowidth, $style, $format, $color) { |
||||
0 ignored issues
–
show
|
|||||
164 | |||||
165 | return array( |
||||
166 | // $attribute => $value |
||||
0 ignored issues
–
show
60% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||||
167 | 'size' => ( $size == 'default' ? get_option('podlove_subscribe_button_default_size', $size) : $size ) |
||||
0 ignored issues
–
show
Are you sure
$size == 'default' ? get...t_size', $size) : $size of type false|mixed|string can be used in concatenation ?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
168 | . self::interpret_autowidth_attribute($autowidth), |
||||
0 ignored issues
–
show
|
|||||
169 | 'style' => ( $style == 'default' ? get_option('podlove_subscribe_button_default_style', $style) : $style ), |
||||
0 ignored issues
–
show
|
|||||
170 | 'format' => ( $format == 'default' ? get_option('podlove_subscribe_button_default_format', $format) : $format ), |
||||
0 ignored issues
–
show
|
|||||
171 | 'color' => ( isset($color) ? $color : get_option('podlove_subscribe_button_default_color', $color) ), |
||||
0 ignored issues
–
show
|
|||||
172 | 'json-data' => 'podcastData' . $this->id |
||||
0 ignored issues
–
show
|
|||||
173 | ); |
||||
0 ignored issues
–
show
|
|||||
174 | } |
||||
0 ignored issues
–
show
|
|||||
175 | |||||
176 | /** |
||||
177 | * Helper function to interpret the given $autowidth value correctly |
||||
178 | * @param string $autowidth |
||||
0 ignored issues
–
show
|
|||||
179 | * @return string |
||||
180 | */ |
||||
181 | private static function interpret_autowidth_attribute($autowidth) { |
||||
0 ignored issues
–
show
|
|||||
182 | if ( $autowidth == 'default' && get_option('podlove_subscribe_button_default_autowidth') !== 'on' ) |
||||
0 ignored issues
–
show
|
|||||
183 | return ''; |
||||
184 | |||||
185 | if ( $autowidth !== 'default' && $autowidth !== 'on' ) |
||||
0 ignored issues
–
show
|
|||||
186 | return ''; |
||||
187 | |||||
188 | return ' auto'; |
||||
189 | } |
||||
0 ignored issues
–
show
|
|||||
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 |