1 | <?php |
||
0 ignored issues
–
show
|
|||
2 | /** |
||
3 | * LSX Search Main Class. |
||
4 | * |
||
5 | * @package lsx-search |
||
6 | */ |
||
7 | class LSX_Search { |
||
0 ignored issues
–
show
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.
You can fix this by adding a namespace to your class: namespace YourVendor;
class YourClass { }
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries. ![]() Class name "LSX_Search" is not in PascalCase format
Classes in PHP are usually named in CamelCase. In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. The whole name starts with a capital letter as well. Thus the name database provider becomes ![]() |
|||
8 | |||
9 | /** |
||
10 | * Holds class instance |
||
11 | * |
||
12 | * @since 1.0.0 |
||
13 | * |
||
14 | * @var object LSX_Search() |
||
15 | */ |
||
16 | protected static $instance = null; |
||
17 | |||
18 | /** |
||
19 | * @var LSX_Search_Admin() |
||
0 ignored issues
–
show
The type
LSX_Search_Admin 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 ![]() |
|||
20 | */ |
||
21 | public $admin; |
||
22 | |||
23 | /** |
||
24 | * @var LSX_Search_Frontend() |
||
0 ignored issues
–
show
The type
LSX_Search_Frontend 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 ![]() |
|||
25 | */ |
||
26 | public $frontend; |
||
27 | |||
28 | /** |
||
29 | * @var LSX_Search_FacetWP() |
||
30 | */ |
||
31 | public $facetwp; |
||
32 | |||
33 | /** |
||
34 | * @var LSX_Search_Shortcode() |
||
35 | */ |
||
36 | public $shortcode; |
||
37 | |||
38 | /** |
||
39 | * LSX_Search constructor |
||
40 | */ |
||
41 | public function __construct() { |
||
0 ignored issues
–
show
|
|||
42 | $this->load_vendors(); |
||
43 | |||
44 | require_once LSX_SEARCH_PATH . '/classes/class-admin.php'; |
||
45 | require_once LSX_SEARCH_PATH . '/classes/class-frontend.php'; |
||
46 | require_once LSX_SEARCH_PATH . '/classes/class-lsx-search-facetwp.php'; |
||
47 | require_once LSX_SEARCH_PATH . '/classes/class-lsx-search-shortcode.php'; |
||
48 | |||
49 | $this->admin = \lsx\search\classes\Admin::get_instance(); |
||
50 | $this->frontend = \lsx\search\classes\Frontend::get_instance(); |
||
51 | $this->facetwp = new LSX_Search_FacetWP(); |
||
52 | $this->shortcode = new LSX_Search_Shortcode(); |
||
53 | } |
||
0 ignored issues
–
show
|
|||
54 | |||
55 | /** |
||
56 | * Return an instance of this class. |
||
57 | * |
||
58 | * @since 1.0.0 |
||
59 | * |
||
60 | * @return object LSX_Search() A single instance of this class. |
||
61 | */ |
||
62 | public static function get_instance() { |
||
0 ignored issues
–
show
|
|||
63 | // If the single instance hasn't been set, set it now. |
||
64 | if ( null === self::$instance ) { |
||
0 ignored issues
–
show
|
|||
65 | self::$instance = new self(); |
||
66 | } |
||
67 | return self::$instance; |
||
68 | } |
||
0 ignored issues
–
show
|
|||
69 | |||
70 | /** |
||
71 | * Loads the plugin functions. |
||
72 | */ |
||
73 | private function load_vendors() { |
||
0 ignored issues
–
show
|
|||
74 | // Configure custom fields. |
||
75 | if ( ! class_exists( 'CMB2' ) ) { |
||
0 ignored issues
–
show
|
|||
76 | require_once LSX_SEARCH_PATH . 'vendor/CMB2/init.php'; |
||
77 | } |
||
78 | } |
||
0 ignored issues
–
show
|
|||
79 | } |
||
80 | |||
81 | /** |
||
82 | * Initiates the LSX Search Plugin |
||
83 | * |
||
84 | * @return object LSX_Search(); |
||
85 | */ |
||
86 | function lsx_search() { |
||
0 ignored issues
–
show
|
|||
87 | global $lsx_search; |
||
88 | $lsx_search = LSX_Search::get_instance(); |
||
89 | return $lsx_search; |
||
90 | } |
||
0 ignored issues
–
show
|
|||
91 | lsx_search(); |
||
92 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.