Completed
Push — develop ( 507546...65eb42 )
by Zack
05:37
created

Core::init()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 38
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 16
nc 2
nop 0
dl 0
loc 38
rs 8.8571
c 0
b 0
f 0
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 15 and the first side effect is on line 5.

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
namespace GV;
3
4
/** If this file is called directly, abort. */
5
if ( ! defined( 'GRAVITYVIEW_DIR' ) )
0 ignored issues
show
Coding Style Best Practice introduced by
It is generally a best practice to always use braces with control structures.

Adding braces to control structures avoids accidental mistakes as your code changes:

// Without braces (not recommended)
if (true)
    doSomething();

// Recommended
if (true) {
    doSomething();
}
Loading history...
6
	die();
7
8
/**
9
 * The core GravityView API.
10
 *
11
 * Returned by the wrapper gravityview() global function, exposes
12
 * all the required public functionality and classes, sets up global
13
 * state depending on current request context, etc.
14
 */
15
final class Core {
16
	/**
17
	 * @var \GV\Core The \GV\Core static instance.
18
	 */
19
	private static $__instance = null;
20
21
	/**
22
	 * @var \GV\Plugin The WordPress plugin context.
23
	 *
24
	 * @api
25
	 * @since future
26
	 */
27
	public $plugin;
28
29
	/**
30
	 * @var \GV\Request The current request.
31
	 *
32
	 * @api
33
	 * @since future
34
	 */
35
	public $request;
36
37
	/**
38
	 * @var \GV\View_Collection The views attached to the current request.
39
	 *
40
	 * @see \GV\Request::$views A shortcut alias.
41
	 * @api
42
	 * @since future
43
	 */
44
	public $views;
45
46
	/**
47
	 * Get the global instance of \GV\Core.
48
	 *
49
	 * @return \GV\Core The global instance of GravityView Core.
50
	 */
51
	public static function get() {
52
		if ( ! self::$__instance instanceof self )
0 ignored issues
show
Coding Style Best Practice introduced by
It is generally a best practice to always use braces with control structures.

Adding braces to control structures avoids accidental mistakes as your code changes:

// Without braces (not recommended)
if (true)
    doSomething();

// Recommended
if (true) {
    doSomething();
}
Loading history...
53
			self::$__instance = new self;
54
		return self::$__instance;
55
	}
56
57
	/**
58
	 * Bootstrap.
59
	 *
60
	 * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
61
	 */
62
	private function __construct() {
63
		self::$__instance = $this;
64
		$this->init();
65
	}
66
67
	/**
68
	 * Early initialization.
69
	 *
70
	 * Loads dependencies, sets up the object, adds hooks, etc.
71
	 *
72
	 * @return void
73
	 */
74
	private function init() {
75
		require_once dirname( __FILE__ ) . '/class-gv-plugin.php';
76
		$this->plugin = Plugin::get();
77
78
		/**
79
		 * Stop all further functionality from loading if the WordPress
80
		 * plugin is incompatible with the current environment.
81
		 *
82
		 * @todo Output incompatibility notices.
83
		 */
84
		if ( ! $this->plugin->is_compatible() ) {
85
			return;
86
		}
87
88
		/** Register the gravityview post type upon WordPress core init. */
89
		require_once $this->plugin->dir( 'future/includes/class-gv-view.php' );
90
		add_action( 'init', array( '\GV\View', 'register_post_type' ) );
91
92
		/** Add rewrite endpoint for single-entry URLs. */
93
		require_once $this->plugin->dir( 'future/includes/class-gv-entry.php' );
94
		add_action( 'init', array( '\GV\Entry', 'add_rewrite_endpoint' ) );
95
96
		/** Generics */
97
		require_once $this->plugin->dir( 'future/includes/class-gv-collection.php' );
98
		require_once $this->plugin->dir( 'future/includes/class-gv-shortcode.php' );
99
100
		/** Shortcodes */
101
		require_once $this->plugin->dir( 'future/includes/class-gv-shortcode-gravityview.php' );
102
		// add_action( 'init', array( '\GV\Shortcodes\gravityview', 'add' ) ); // @todo uncomment when original is stubbed
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% 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...
103
104
		/** Get the View_Collection ready. */
105
		require_once $this->plugin->dir( 'future/includes/class-gv-collection-view.php' );
106
107
		/** Initialize the current request. For now we assume a default WordPress frontent context. */
108
		require_once $this->plugin->dir( 'future/includes/class-gv-request.php' );
109
		$this->request = new Frontend_Request();
110
		$this->views = &$this->request->views;
111
	}
112
113
	private function __clone() { }
114
115
	private function __wakeup() { }
116
}
117