ShortcodeUI   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 64
rs 10
c 0
b 0
f 0
ccs 0
cts 12
cp 0
wmc 3
lcom 1
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A register() 0 10 2
1
<?php
2
/**
3
 * Bright Nucleus Shortcode Component.
4
 *
5
 * @package   BrightNucleus\Shortcode
6
 * @author    Alain Schlesser <[email protected]>
7
 * @license   MIT
8
 * @link      http://www.brightnucleus.com/
9
 * @copyright 2015-2016 Alain Schlesser, Bright Nucleus
10
 */
11
12
namespace BrightNucleus\Shortcode;
13
14
use BrightNucleus\Config\ConfigInterface;
15
use BrightNucleus\Config\ConfigTrait;
16
use BrightNucleus\Dependency\DependencyManagerInterface as DependencyManager;
17
use BrightNucleus\Exception\RuntimeException;
18
19
/**
20
 * Shortcode UI Class.
21
 *
22
 * @since   0.1.0
23
 *
24
 * @package BrightNucleus\Shortcode
25
 * @author  Alain Schlesser <[email protected]>
26
 */
27
class ShortcodeUI implements ShortcodeUIInterface {
28
29
	use ConfigTrait;
30
	use CheckNeedTrait;
31
32
	/**
33
	 * Name of the shortcode handler.
34
	 *
35
	 * @since 0.1.0
36
	 *
37
	 * @var string
38
	 */
39
	protected $shortcode_tag;
40
41
	/**
42
	 * Dependencies to be enqueued.
43
	 *
44
	 * @since 0.1.0
45
	 *
46
	 * @var DependencyManager
47
	 */
48
	protected $dependencies;
49
50
	/**
51
	 * Instantiate Basic Shortcode UI.
52
	 *
53
	 * @since 1.0.
54
	 *
55
	 * @param string                 $shortcode_tag Tag of the Shortcode.
56
	 * @param ConfigInterface        $config        Configuration settings.
57
	 * @param DependencyManager|null $dependencies  Optional. Dependencies that
58
	 *                                              need to be enqueued.
59
	 * @throws RuntimeException If the config could not be processed.
60
	 */
61
	public function __construct(
62
		$shortcode_tag,
63
		ConfigInterface $config,
64
		DependencyManager $dependencies = null
65
	) {
66
		$this->processConfig( $config );
67
68
		$this->shortcode_tag = $shortcode_tag;
69
		$this->dependencies  = $dependencies;
70
	}
71
72
	/**
73
	 * Register the shortcode UI handler function with WordPress.
74
	 *
75
	 * @since 0.1.0
76
	 *
77
	 * @param mixed $context Data about the context in which the call is made.
78
	 * @return void
79
	 */
80
	public function register( $context = null ) {
81
		if ( ! $this->is_needed() ) {
82
			return;
83
		}
84
85
		\shortcode_ui_register_for_shortcode(
86
			$this->shortcode_tag,
87
			$this->config
88
		);
89
	}
90
}
91