Passed
Push — develop ( 7b2b20...7eda82 )
by Paul
04:02
created

Application   A

Complexity

Total Complexity 18

Size/Duplication

Total Lines 158
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 158
ccs 2
cts 2
cp 1
rs 10
c 1
b 0
f 0
wmc 18
lcom 1
cbo 4

11 Methods

Rating   Name   Duplication   Size   Complexity  
A prefix() 0 4 1
A __construct() 0 15 2
A init() 0 18 3
A environment() 0 8 3
A onActivation() 0 3 1
A onDeactivation() 0 3 1
A path() 0 4 1
A render() 0 13 2
A url() 0 4 1
A bootstrap() 0 19 2
A registerAliases() 0 8 1
1
<?php
2
3
namespace GeminiLabs\Pollux;
4
5
use GeminiLabs\Pollux\AliasLoader;
6
use GeminiLabs\Pollux\Config\ConfigManager;
7
use GeminiLabs\Pollux\Container;
8
use GeminiLabs\Pollux\Facade;
9
use GeminiLabs\Pollux\GateKeeper;
10
use GeminiLabs\Pollux\PostType\PostType;
11
12
final class Application extends Container
13
{
14
	const PREFIX = 'pollux_';
15
16
	public $config;
17
	public $file;
18
	public $gatekeeper;
19
	public $id;
20
	public $name;
21
	public $notices = [];
22
	public $version;
23
24
	/**
25
	 * @return string
26
	 */
27
	public static function prefix()
28
	{
29
		return apply_filters( 'pollux/prefix', self::PREFIX );
30
	}
31
32
	public function __construct()
33
	{
34
		$this->file = realpath( dirname( dirname( __FILE__ )) . '/pollux.php' );
35
		$this->gatekeeper = new GateKeeper( plugin_basename( $this->file ));
36
37
		$data = get_file_data( $this->file, array(
38
			'id' => 'Text Domain',
39
			'name' => 'Plugin Name',
40
			'version' => 'Version',
41
		), 'plugin' );
42
43
		foreach( $data as $key => $value ) {
44
			$this->$key = $value;
45
		}
46
	}
47
48
	/**
49
	 * The Application entry point
50
	 *
51
	 * @return void
52
	 */
53
	public function init()
54
	{
55
		$this->bootstrap();
56
57
		$basename = plugin_basename( $this->file );
58
		$controller = $this->make( 'Controller' );
59
60
		add_action( 'admin_enqueue_scripts',           array( $controller, 'registerAssets' ));
61
		add_action( 'admin_init',                      array( $controller, 'removeDashboardWidgets' ));
62
		add_action( 'wp_before_admin_bar_render',      array( $controller, 'removeWordPressMenu' ));
63
		add_filter( "plugin_action_links_{$basename}", array( $controller, 'filterPluginLinks' ));
64
		add_filter( 'admin_footer_text',               array( $controller, 'filterWordPressFooter' ));
65
66
		// Disallow indexing of the site on non-production environments
67
		if( !$this->environment( 'production' ) && !is_admin() ) {
68
			add_filter( 'pre_option_blog_public', '__return_zero' );
69
		}
70
	}
71
72
	/**
73
	 * @param string $checkFor
74
	 * @return string|bool
75
	 */
76
	public function environment( $checkFor = '' )
77
	{
78
		$environment = defined( 'WP_ENV' ) ? WP_ENV : 'production';
79
		if( !empty( $checkFor )) {
80
			return $environment == $checkFor;
81
		}
82
		return $environment;
83
	}
84
85
	/**
86
	 * @return void
87
	 */
88 14
	public function onActivation()
89
	{
90 14
	}
91
92
	/**
93
	 * @return void
94
	 */
95
	public function onDeactivation()
96
	{
97
	}
98
99
	/**
100
	 * @param string $file
101
	 * @return string
102
	 */
103
	public function path( $file = '' )
104
	{
105
		return plugin_dir_path( $this->file ) . ltrim( trim( $file ), '/' );
106
	}
107
108
	/**
109
	 * @param string $view
110
	 * @return bool
111
	 */
112
	public function render( $view, array $data = [] )
113
	{
114
		$file = apply_filters( 'pollux/views/file',
115
			$this->path( sprintf( 'views/%s.php', str_replace( '.php', '', $view ))),
116
			$view,
117
			$data
118
		);
119
		if( file_exists( $file )) {
120
			extract( $data );
121
			return include $file;
122
		}
123
		return false;
124
	}
125
126
	/**
127
	 * @param string $path
128
	 * @return string
129
	 */
130
	public function url( $path = '' )
131
	{
132
		return esc_url( plugin_dir_url( $this->file ) . ltrim( trim( $path ), '/' ));
133
	}
134
135
	/**
136
	 * @return void
137
	 */
138
	protected function bootstrap()
139
	{
140
		Facade::clearResolvedInstances();
141
		Facade::setFacadeApplication( $this );
142
		$this->registerAliases();
143
		$this->config = $this->make( ConfigManager::class )->compile();
144
		$classNames = array(
145
			'Config\Config',
146
			'MetaBox\MetaBox',
147
			'PostType\Archive',
148
			'PostType\DisablePosts',
149
			'PostType\PostType',
150
			'Settings\Settings',
151
			'Taxonomy\Taxonomy',
152
		);
153
		foreach( $classNames as $className ) {
154
			$this->make( $className )->init();
155
 		}
156
	}
157
158
	/**
159
	 * @return void
160
	 */
161
	protected function registerAliases()
162
	{
163
		AliasLoader::getInstance( apply_filters( 'pollux/aliases', array(
164
			'ArchiveMeta' => 'GeminiLabs\Pollux\Facades\ArchiveMeta',
165
			'PostMeta' => 'GeminiLabs\Pollux\Facades\PostMeta',
166
			'SiteMeta' => 'GeminiLabs\Pollux\Facades\SiteMeta',
167
		)))->register();
168
	}
169
}
170