1 | <?php |
||||
2 | /** |
||||
3 | * LSX_Sharing_Button |
||||
4 | * |
||||
5 | * @package lsx-sharing |
||||
6 | */ |
||||
7 | |||||
8 | namespace lsx\sharing\classes\frontend; |
||||
9 | |||||
10 | /** |
||||
11 | * LSX Sharing buttons class. |
||||
12 | * |
||||
13 | * @package lsx-sharing |
||||
14 | */ |
||||
15 | class Button { |
||||
16 | |||||
17 | |||||
18 | /** |
||||
19 | * Services available. |
||||
20 | * |
||||
21 | * @var array |
||||
22 | */ |
||||
23 | public $services = array( |
||||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||||
24 | 'facebook', |
||||
25 | 'twitter', |
||||
26 | 'pinterest', |
||||
27 | ); |
||||
28 | |||||
29 | /** |
||||
30 | * Current service. |
||||
31 | * |
||||
32 | * @var string |
||||
33 | */ |
||||
34 | public $service = ''; |
||||
35 | |||||
36 | /** |
||||
0 ignored issues
–
show
|
|||||
37 | * Constructor. |
||||
38 | */ |
||||
39 | public function __construct( $service, $options, $prefix = 'sharing' ) { |
||||
0 ignored issues
–
show
|
|||||
40 | $this->options = $options; |
||||
0 ignored issues
–
show
|
|||||
41 | if ( ! in_array($service, $this->services, true) ) { |
||||
0 ignored issues
–
show
|
|||||
42 | return; |
||||
43 | } |
||||
0 ignored issues
–
show
|
|||||
44 | if ( \lsx\sharing\includes\functions\is_button_disabled('global', $service) || \lsx\sharing\includes\functions\is_button_disabled($prefix, $service) ) { |
||||
0 ignored issues
–
show
|
|||||
45 | return ''; |
||||
46 | } |
||||
0 ignored issues
–
show
|
|||||
47 | $this->service = $service; |
||||
48 | } |
||||
0 ignored issues
–
show
|
|||||
49 | |||||
50 | /** |
||||
0 ignored issues
–
show
|
|||||
51 | * Get service link to share. |
||||
52 | */ |
||||
53 | public function get_link( $post ) { |
||||
54 | if ( empty($post) ) { |
||||
0 ignored issues
–
show
|
|||||
55 | return ''; |
||||
56 | } |
||||
0 ignored issues
–
show
|
|||||
57 | |||||
58 | if ( 'email' === $this->service ) { |
||||
0 ignored issues
–
show
|
|||||
59 | return $this->get_link_email($post); |
||||
0 ignored issues
–
show
The call to
lsx\sharing\classes\fron...utton::get_link_email() has too many arguments starting with $post .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above. ![]() |
|||||
60 | } elseif ( 'facebook' === $this->service ) { |
||||
0 ignored issues
–
show
|
|||||
61 | return $this->get_link_facebook($post); |
||||
0 ignored issues
–
show
|
|||||
62 | } elseif ( 'twitter' === $this->service ) { |
||||
0 ignored issues
–
show
|
|||||
63 | return $this->get_link_twitter($post); |
||||
0 ignored issues
–
show
|
|||||
64 | } elseif ( 'pinterest' === $this->service ) { |
||||
0 ignored issues
–
show
|
|||||
65 | return $this->get_link_pinterest($post); |
||||
0 ignored issues
–
show
|
|||||
66 | } |
||||
67 | } |
||||
0 ignored issues
–
show
|
|||||
68 | |||||
69 | /** |
||||
0 ignored issues
–
show
|
|||||
70 | * Get Facebook link to share. |
||||
71 | */ |
||||
72 | public function get_link_facebook( $post ) { |
||||
73 | $permalink = get_permalink($post->ID); |
||||
0 ignored issues
–
show
|
|||||
74 | $permalink = apply_filters('lsx_sharing_facebook_url', $permalink, $post); |
||||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 2 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. ![]() |
|||||
75 | $title = apply_filters('the_title', $post->post_title); |
||||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 5 spaces
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. ![]() |
|||||
76 | |||||
77 | return 'https://www.facebook.com/sharer.php?display=page&u=' . rawurlencode($permalink) . '&t=' . rawurlencode($title); |
||||
0 ignored issues
–
show
It seems like
$permalink can also be of type false ; however, parameter $string of rawurlencode() 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
![]() |
|||||
78 | } |
||||
0 ignored issues
–
show
|
|||||
79 | |||||
80 | /** |
||||
0 ignored issues
–
show
|
|||||
81 | * Get Twitter link to share. |
||||
82 | */ |
||||
83 | public function get_link_twitter( $post ) { |
||||
84 | $permalink = get_permalink($post->ID); |
||||
0 ignored issues
–
show
|
|||||
85 | $permalink = apply_filters('lsx_sharing_twitter_url', $permalink, $post); |
||||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 2 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. ![]() |
|||||
86 | $title = apply_filters('the_title', $post->post_title); |
||||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 5 spaces
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. ![]() |
|||||
87 | |||||
88 | if ( function_exists('mb_stripos') ) { |
||||
0 ignored issues
–
show
|
|||||
89 | $strlen = 'mb_strlen'; |
||||
90 | $substr = 'mb_substr'; |
||||
91 | } else { |
||||
92 | $strlen = 'strlen'; |
||||
93 | $substr = 'substr'; |
||||
94 | } |
||||
95 | |||||
96 | $short_url_length = 24; |
||||
97 | |||||
98 | if ( ( $strlen($title) + $short_url_length ) > 140 ) { |
||||
0 ignored issues
–
show
|
|||||
99 | $text = $substr($title, 0, ( 140 - $short_url_length - 1 )) . "\xE2\x80\xA6"; |
||||
0 ignored issues
–
show
|
|||||
100 | } else { |
||||
101 | $text = $title; |
||||
102 | } |
||||
103 | |||||
104 | return 'https://twitter.com/intent/tweet?text=' . rawurlencode($text) . '&url=' . rawurlencode($permalink); |
||||
0 ignored issues
–
show
It seems like
$permalink can also be of type false ; however, parameter $string of rawurlencode() 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
![]() |
|||||
105 | } |
||||
0 ignored issues
–
show
|
|||||
106 | |||||
107 | /** |
||||
0 ignored issues
–
show
|
|||||
108 | * Get Pinterest link to share. |
||||
109 | */ |
||||
110 | public function get_link_pinterest( $post ) { |
||||
111 | $image = ''; |
||||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 5 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. ![]() |
|||||
112 | $permalink = get_permalink($post->ID); |
||||
0 ignored issues
–
show
|
|||||
113 | $permalink = apply_filters('lsx_sharing_pinterest_url', $permalink, $post); |
||||
0 ignored issues
–
show
|
|||||
114 | $title = apply_filters('the_title', $post->post_title); |
||||
0 ignored issues
–
show
|
|||||
115 | |||||
116 | if ( ! has_post_thumbnail($post) ) { |
||||
0 ignored issues
–
show
|
|||||
117 | if ( class_exists('lsx\legacy\Placeholders') ) { |
||||
0 ignored issues
–
show
|
|||||
118 | $image = \lsx\legacy\Placeholders::placeholder_url(null, $post->post_type); |
||||
0 ignored issues
–
show
|
|||||
119 | } elseif ( class_exists('LSX_Placeholders') ) { |
||||
0 ignored issues
–
show
|
|||||
120 | $image = \LSX_Placeholders::placeholder_url(null, $post->post_type); |
||||
0 ignored issues
–
show
The type
LSX_Placeholders was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||||
121 | } |
||||
122 | } else { |
||||
123 | $image = get_the_post_thumbnail_url($post->ID, 'large'); |
||||
0 ignored issues
–
show
|
|||||
124 | } |
||||
125 | |||||
126 | return 'https://www.pinterest.com/pin/create/button/?url=' . rawurlencode($permalink) . '&media=' . rawurlencode($image) . '&description=' . rawurlencode($title); |
||||
0 ignored issues
–
show
It seems like
$permalink can also be of type false ; however, parameter $string of rawurlencode() 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
![]() |
|||||
127 | } |
||||
0 ignored issues
–
show
|
|||||
128 | |||||
129 | /** |
||||
130 | * Get Email Link. |
||||
131 | */ |
||||
132 | public function get_link_email() { } |
||||
0 ignored issues
–
show
|
|||||
133 | } |
||||
134 |