Completed
Pull Request — staging (#840)
by
unknown
15:43
created

PluginFactory::create()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
1
<?php
2
/**
3
 * YIKES Inc. Easy Mailchimp Forms Plugin.
4
 *
5
 * @package   YIKES\EasyForms
6
 * @author    Freddie Mixell
7
 * @license   GPL2
8
 */
9
10
namespace YIKES\EasyForms;
11
12
use YIKES\EasyForms\PluginHelper;
13
use YIKES\EasyForms\Shortcode\EasyFormsShortcode;
14
use YIKES\EasyForms\Util\Debugger;
15
use YIKES\EasyForms\Recaptcha\Recaptcha;
16
17
/**
18
 * Class PluginFactory
19
 *
20
 * @since   %VERSION%
21
 *
22
 * @package YIKES\EasyForms
23
 * @author  Freddie Mixell
24
 */
25
final class PluginFactory {
26
27
	use PluginHelper;
28
29
	/**
30
	 * Create and return an instance of the plugin.
31
	 *
32
	 * This always returns a shared instance.
33
	 *
34
	 * @since %VERSION%
35
	 *
36
	 * @return Plugin The plugin instance.
37
	 */
38
	public function create() {
39
		static $plugin = null;
40
41
		if ( null === $plugin ) {
42
			$plugin = new Plugin( $this->get_service_container() );
43
		}
44
45
		return $plugin;
46
	}
47
48
	/**
49
	 * Get the service container for our class.
50
	 *
51
	 * @since %VERSION%
52
	 * @return Container
53
	 */
54
	private function get_service_container() {
55
56
		$services = new Container();
57
58
		// Start Debugging
59
		$services->add_service( Debugger::class );
60
61
		// Register Shortcode
62
		$services->add_service( EasyFormsShortcode::class );
63
64
		// Register Recaptcha
65
		$services->add_service( Recaptcha::class );
66
67
		return $services;
68
	}
69
}