Issues (924)

classes/class-sharing.php (53 issues)

1
<?php
2
/**
3
 * LSX_Sharing
4
 *
5
 * @package lsx-sharing
6
 */
0 ignored issues
show
There must be exactly one blank line after the file comment
Loading history...
7
namespace lsx\sharing;
8
9
/**
10
 * LSX Sharing class.
11
 *
12
 * @package lsx-sharing
13
 */
14
class Sharing {
15
16
17
    /**
18
     * Holds class instance
19
     *
20
     * @since 1.0.0
21
     *
22
     * @var object \lsx\search\Sharing()
23
     */
24
    protected static $instance = null;
0 ignored issues
show
Expected 1 blank line(s) before first member var; 2 found
Loading history...
25
26
    /**
27
     * Holds class instance
28
     *
29
     * @since 1.0.0
30
     *
31
     * @var object \lsx\search\classes\Admin()
32
     */
33
    public $admin = false;
34
35
    /**
36
     * If we are using the new options or not.
37
     *
38
     * @var boolean
39
     */
40
    public $is_new_options = false;
41
42
    /**
43
     * The options for the plugin.
44
     *
45
     * @var array
46
     */
47
    public $options = array();
48
49
    /**
50
     * Constructor.
51
     */
52
    public function __construct() {
0 ignored issues
show
Expected 2 blank lines before function; 1 found
Loading history...
53
         add_action('init', array( $this, 'set_options' ), 50);
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...
54
        $this->load_vendors();
55
        $this->load_includes();
56
        $this->load_classes();
57
    }
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...
58
59
    /**
60
     * Return an instance of this class.
61
     *
62
     * @since 1.0.0
63
     *
64
     * @return object \lsx\member_directory\search\Admin()    A single instance of this class.
65
     */
66
    public static function get_instance() {
67
         // If the single instance hasn't been set, set it now.
0 ignored issues
show
Found precision alignment of 1 spaces.
Loading history...
68
        if ( null === self::$instance ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
69
            self::$instance = new self();
70
        }
0 ignored issues
show
No blank line found after control structure
Loading history...
71
        return self::$instance;
72
    }
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...
73
74
    /**
75
     * Loads the plugin functions.
76
     */
77
    private function load_vendors() {
78
         // Configure custom fields.
0 ignored issues
show
Found precision alignment of 1 spaces.
Loading history...
79
        if ( ! class_exists('CMB2') ) {
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...
80
            include_once LSX_SHARING_PATH . 'vendor/CMB2/init.php';
81
        }
82
    }
0 ignored issues
show
Expected 2 blank lines after function; 0 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
83
    /**
84
     * Loads the plugin functions.
85
     */
86
    private function load_includes() {
87
         include_once LSX_SHARING_PATH . '/includes/functions.php';
0 ignored issues
show
Found precision alignment of 1 spaces.
Loading history...
88
    }
0 ignored issues
show
Expected 2 blank lines after function; 0 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
89
    /**
90
     * Loads the plugin functions.
91
     */
92
    private function load_classes() {
93
         include_once LSX_SHARING_PATH . '/classes/class-admin.php';
0 ignored issues
show
Found precision alignment of 1 spaces.
Loading history...
94
        global $lsx_sharing_admin;
95
        $this->admin = \lsx\sharing\classes\Admin::get_instance();
96
        $lsx_sharing_admin;
97
98
        include_once LSX_SHARING_PATH . '/classes/class-frontend.php';
99
        $this->frontend = \lsx\sharing\classes\Frontend::get_instance();
0 ignored issues
show
Bug Best Practice introduced by
The property frontend does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
100
        global $lsx_sharing;
101
        $lsx_sharing = $this->frontend->output;
102
103
        include_once LSX_SHARING_PATH . '/classes/deprecated/class-lsx-sharing.php';
104
    }
0 ignored issues
show
Expected 2 blank lines after function; 0 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
105
    /**
106
     * Set options.
107
     */
108
    public function set_options() {
109
         if ( function_exists('tour_operator') ) {
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...
110
            $this->options = get_option('_lsx-to_settings', false);
0 ignored issues
show
Documentation Bug introduced by
It seems like get_option('_lsx-to_settings', false) can also be of type false. However, the property $options is declared as type array. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
111
        } else {
0 ignored issues
show
Closing brace indented incorrectly; expected 9 spaces, found 8
Loading history...
112
            $this->options = get_option('_lsx_settings', false);
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
114
            if ( false === $this->options ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
115
                $this->options = get_option('_lsx_lsx-settings', false);
0 ignored issues
show
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
116
            }
117
        }
118
119
        $new_options = get_option('lsx-sharing-settings');
0 ignored issues
show
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
120
        if ( ! empty($new_options) ) {
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...
121
            if ( '' !== $new_options && false !== $new_options ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
122
                $this->is_new_options = true;
123
                $this->options        = $new_options;
124
            }
125
        }
126
    }
0 ignored issues
show
Expected 2 blank lines after function; 0 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
127
}
128