Issues (924)

classes/frontend/class-button.php (119 issues)

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
Expected 1 blank line(s) before first member var; 2 found
Loading history...
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
Coding Style Documentation introduced by
Doc comment for parameter "$service" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$options" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$prefix" missing
Loading history...
37
     * Constructor.
38
     */
39
    public function __construct( $service, $options, $prefix = 'sharing' ) {
0 ignored issues
show
Expected 2 blank lines before function; 1 found
Loading history...
40
         $this->options = $options;
0 ignored issues
show
Bug Best Practice introduced by
The property options does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
Found precision alignment of 1 spaces.
Loading history...
41
        if ( ! in_array($service, $this->services, true) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
42
            return;
43
        }
0 ignored issues
show
No blank line found after control structure
Loading history...
44
        if ( \lsx\sharing\includes\functions\is_button_disabled('global', $service) || \lsx\sharing\includes\functions\is_button_disabled($prefix, $service) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
45
            return '';
46
        }
0 ignored issues
show
No blank line found after control structure
Loading history...
47
        $this->service = $service;
48
    }
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
49
50
    /**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$post" missing
Loading history...
51
     * Get service link to share.
52
     */
53
    public function get_link( $post ) {
54
         if ( empty($post) ) {
0 ignored issues
show
Found precision alignment of 1 spaces.
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
55
            return '';
56
        }
0 ignored issues
show
Closing brace indented incorrectly; expected 9 spaces, found 8
Loading history...
57
58
        if ( 'email' === $this->service ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
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 ignore-call  annotation

59
            return $this->/** @scrutinizer ignore-call */ get_link_email($post);

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.

Loading history...
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
60
        } elseif ( 'facebook' === $this->service ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
61
            return $this->get_link_facebook($post);
0 ignored issues
show
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
62
        } elseif ( 'twitter' === $this->service ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
63
            return $this->get_link_twitter($post);
0 ignored issues
show
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
64
        } elseif ( 'pinterest' === $this->service ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
65
            return $this->get_link_pinterest($post);
0 ignored issues
show
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
66
        }
67
    }
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
68
69
    /**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$post" missing
Loading history...
70
     * Get Facebook link to share.
71
     */
72
    public function get_link_facebook( $post ) {
73
         $permalink = get_permalink($post->ID);
0 ignored issues
show
Found precision alignment of 1 spaces.
Loading history...
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
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.

Loading history...
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
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.

Loading history...
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
76
77
        return 'https://www.facebook.com/sharer.php?display=page&u=' . rawurlencode($permalink) . '&t=' . rawurlencode($title);
0 ignored issues
show
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
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 ignore-type  annotation

77
        return 'https://www.facebook.com/sharer.php?display=page&u=' . rawurlencode(/** @scrutinizer ignore-type */ $permalink) . '&t=' . rawurlencode($title);
Loading history...
78
    }
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
79
80
    /**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$post" missing
Loading history...
81
     * Get Twitter link to share.
82
     */
83
    public function get_link_twitter( $post ) {
84
         $permalink = get_permalink($post->ID);
0 ignored issues
show
Found precision alignment of 1 spaces.
Loading history...
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
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.

Loading history...
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
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.

Loading history...
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
87
88
        if ( function_exists('mb_stripos') ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
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
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
99
            $text = $substr($title, 0, ( 140 - $short_url_length - 1 )) . "\xE2\x80\xA6";
0 ignored issues
show
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
100
        } else {
101
            $text = $title;
102
        }
103
104
        return 'https://twitter.com/intent/tweet?text=' . rawurlencode($text) . '&url=' . rawurlencode($permalink);
0 ignored issues
show
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
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 ignore-type  annotation

104
        return 'https://twitter.com/intent/tweet?text=' . rawurlencode($text) . '&url=' . rawurlencode(/** @scrutinizer ignore-type */ $permalink);
Loading history...
105
    }
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
106
107
    /**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$post" missing
Loading history...
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.

Loading history...
112
        $permalink = get_permalink($post->ID);
0 ignored issues
show
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
113
        $permalink = apply_filters('lsx_sharing_pinterest_url', $permalink, $post);
0 ignored issues
show
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
114
        $title     = apply_filters('the_title', $post->post_title);
0 ignored issues
show
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
115
116
        if ( ! has_post_thumbnail($post) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
117
            if ( class_exists('lsx\legacy\Placeholders') ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
118
                $image = \lsx\legacy\Placeholders::placeholder_url(null, $post->post_type);
0 ignored issues
show
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
119
            } elseif ( class_exists('LSX_Placeholders') ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
121
            }
122
        } else {
123
            $image = get_the_post_thumbnail_url($post->ID, 'large');
0 ignored issues
show
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
124
        }
125
126
        return 'https://www.pinterest.com/pin/create/button/?url=' . rawurlencode($permalink) . '&media=' . rawurlencode($image) . '&description=' . rawurlencode($title);
0 ignored issues
show
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
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 ignore-type  annotation

126
        return 'https://www.pinterest.com/pin/create/button/?url=' . rawurlencode(/** @scrutinizer ignore-type */ $permalink) . '&media=' . rawurlencode($image) . '&description=' . rawurlencode($title);
Loading history...
127
    }
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected 2 blank lines after function; 1 found
Loading history...
128
129
    /**
130
     * Get Email Link.
131
     */
132
    public function get_link_email() {     }
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected 2 blank lines after function; 0 found
Loading history...
133
}
134