Passed
Push — trunk ( 56713e...dd4a77 )
by Justin
04:35
created

CMB2_Bootstrap_242_Trunk   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 115
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 12
c 1
b 0
f 0
dl 0
loc 115
ccs 0
cts 34
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A l10ni18n() 0 16 4
A initiate() 0 5 2
B include_cmb() 0 26 4
A __construct() 0 10 2
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 70 and the first side effect is on line 192.

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.

Loading history...
2
/**
3
 * The initation loader for CMB2, and the main plugin file.
4
 *
5
 * @category     WordPress_Plugin
6
 * @package      CMB2
7
 * @author       CMB2 team
8
 * @license      GPL-2.0+
9
 * @link         https://cmb2.io
10
 *
11
 * Plugin Name:  CMB2
12
 * Plugin URI:   https://github.com/CMB2/CMB2
13
 * Description:  CMB2 will create metaboxes and forms with custom fields that will blow your mind.
14
 * Author:       CMB2 team
15
 * Author URI:   https://cmb2.io
16
 * Contributors: Justin Sternberg (@jtsternberg / dsgnwrks.pro)
17
 *               WebDevStudios (@webdevstudios / webdevstudios.com)
18
 *               Zao (zao.is)
19
 *               Human Made (@humanmadeltd / hmn.md)
20
 *               Jared Atchison (@jaredatch / jaredatchison.com)
21
 *               Bill Erickson (@billerickson / billerickson.net)
22
 *               Andrew Norcross (@norcross / andrewnorcross.com)
23
 *
24
 * Version:      2.4.2
25
 *
26
 * Text Domain:  cmb2
27
 * Domain Path:  languages
28
 *
29
 *
30
 * Released under the GPL license
31
 * http://www.opensource.org/licenses/gpl-license.php
32
 *
33
 * This is an add-on for WordPress
34
 * https://wordpress.org/
35
 *
36
 * **********************************************************************
37
 * This program is free software; you can redistribute it and/or modify
38
 * it under the terms of the GNU General Public License as published by
39
 * the Free Software Foundation; either version 2 of the License, or
40
 * (at your option) any later version.
41
 *
42
 * This program is distributed in the hope that it will be useful,
43
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
44
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
45
 * GNU General Public License for more details.
46
 * **********************************************************************
47
 */
48
49
/**
50
 * *********************************************************************
51
 *               You should not edit the code below
52
 *               (or any code in the included files)
53
 *               or things might explode!
54
 * ***********************************************************************
55
 */
56
57
if ( ! class_exists( 'CMB2_Bootstrap_242_Trunk', false ) ) {
58
59
	/**
60
	 * Handles checking for and loading the newest version of CMB2
61
	 *
62
	 * @since  2.0.0
63
	 *
64
	 * @category  WordPress_Plugin
65
	 * @package   CMB2
66
	 * @author    CMB2 team
67
	 * @license   GPL-2.0+
68
	 * @link      https://cmb2.io
69
	 */
70
	class CMB2_Bootstrap_242_Trunk {
71
72
		/**
73
		 * Current version number
74
		 *
75
		 * @var   string
76
		 * @since 1.0.0
77
		 */
78
		const VERSION = '2.4.2';
79
80
		/**
81
		 * Current version hook priority.
82
		 * Will decrement with each release
83
		 *
84
		 * @var   int
85
		 * @since 2.0.0
86
		 */
87
		const PRIORITY = 9966;
88
89
		/**
90
		 * Single instance of the CMB2_Bootstrap_242_Trunk object
91
		 *
92
		 * @var CMB2_Bootstrap_242_Trunk
93
		 */
94
		public static $single_instance = null;
95
96
		/**
97
		 * Creates/returns the single instance CMB2_Bootstrap_242_Trunk object
98
		 *
99
		 * @since  2.0.0
100
		 * @return CMB2_Bootstrap_242_Trunk Single instance object
101
		 */
102
		public static function initiate() {
103
			if ( null === self::$single_instance ) {
104
				self::$single_instance = new self();
105
			}
106
			return self::$single_instance;
107
		}
108
109
		/**
110
		 * Starts the version checking process.
111
		 * Creates CMB2_LOADED definition for early detection by other scripts
112
		 *
113
		 * Hooks CMB2 inclusion to the init hook on a high priority which decrements
114
		 * (increasing the priority) with each version release.
115
		 *
116
		 * @since 2.0.0
117
		 */
118
		private function __construct() {
119
			/**
120
			 * A constant you can use to check if CMB2 is loaded
121
			 * for your plugins/themes with CMB2 dependency
122
			 */
123
			if ( ! defined( 'CMB2_LOADED' ) ) {
124
				define( 'CMB2_LOADED', self::PRIORITY );
125
			}
126
127
			add_action( 'init', array( $this, 'include_cmb' ), self::PRIORITY );
128
		}
129
130
		/**
131
		 * A final check if CMB2 exists before kicking off our CMB2 loading.
132
		 * CMB2_VERSION and CMB2_DIR constants are set at this point.
133
		 *
134
		 * @since  2.0.0
135
		 */
136
		public function include_cmb() {
137
			if ( class_exists( 'CMB2', false ) ) {
138
				return;
139
			}
140
141
			if ( ! defined( 'CMB2_VERSION' ) ) {
142
				define( 'CMB2_VERSION', self::VERSION );
143
			}
144
145
			if ( ! defined( 'CMB2_DIR' ) ) {
146
				define( 'CMB2_DIR', trailingslashit( dirname( __FILE__ ) ) );
0 ignored issues
show
Bug introduced by
The function trailingslashit was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

146
				define( 'CMB2_DIR', /** @scrutinizer ignore-call */ trailingslashit( dirname( __FILE__ ) ) );
Loading history...
147
			}
148
149
			$this->l10ni18n();
150
151
			// Include helper functions.
152
			require_once CMB2_DIR . 'includes/CMB2_Base.php';
153
			require_once CMB2_DIR . 'includes/CMB2.php';
154
			require_once CMB2_DIR . 'includes/helper-functions.php';
155
156
			// Now kick off the class autoloader.
157
			spl_autoload_register( 'cmb2_autoload_classes' );
158
159
			// Kick the whole thing off.
160
			require_once( cmb2_dir( 'bootstrap.php' ) );
161
			cmb2_bootstrap();
162
		}
163
164
		/**
165
		 * Registers CMB2 text domain path
166
		 *
167
		 * @since  2.0.0
168
		 */
169
		public function l10ni18n() {
170
171
			$loaded = load_plugin_textdomain( 'cmb2', false, '/languages/' );
0 ignored issues
show
Bug introduced by
The function load_plugin_textdomain was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

171
			$loaded = /** @scrutinizer ignore-call */ load_plugin_textdomain( 'cmb2', false, '/languages/' );
Loading history...
172
173
			if ( ! $loaded ) {
174
				$loaded = load_muplugin_textdomain( 'cmb2', '/languages/' );
0 ignored issues
show
Bug introduced by
The function load_muplugin_textdomain was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

174
				$loaded = /** @scrutinizer ignore-call */ load_muplugin_textdomain( 'cmb2', '/languages/' );
Loading history...
175
			}
176
177
			if ( ! $loaded ) {
178
				$loaded = load_theme_textdomain( 'cmb2', get_stylesheet_directory() . '/languages/' );
0 ignored issues
show
Bug introduced by
The function load_theme_textdomain was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

178
				$loaded = /** @scrutinizer ignore-call */ load_theme_textdomain( 'cmb2', get_stylesheet_directory() . '/languages/' );
Loading history...
Bug introduced by
The function get_stylesheet_directory was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

178
				$loaded = load_theme_textdomain( 'cmb2', /** @scrutinizer ignore-call */ get_stylesheet_directory() . '/languages/' );
Loading history...
179
			}
180
181
			if ( ! $loaded ) {
182
				$locale = apply_filters( 'plugin_locale', get_locale(), 'cmb2' );
0 ignored issues
show
Bug introduced by
The function get_locale was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

182
				$locale = apply_filters( 'plugin_locale', /** @scrutinizer ignore-call */ get_locale(), 'cmb2' );
Loading history...
183
				$mofile = dirname( __FILE__ ) . '/languages/cmb2-' . $locale . '.mo';
184
				load_textdomain( 'cmb2', $mofile );
0 ignored issues
show
Bug introduced by
The function load_textdomain was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

184
				/** @scrutinizer ignore-call */ 
185
    load_textdomain( 'cmb2', $mofile );
Loading history...
185
			}
186
187
		}
188
189
	}
190
191
	// Make it so...
192
	CMB2_Bootstrap_242_Trunk::initiate();
193
194
}// End if().
0 ignored issues
show
Unused Code Comprehensibility introduced by
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.

Loading history...
195