Completed
Push — fix/markdown-parser-breaking-s... ( 441f6d...6ae5e6 )
by Jeremy
335:56 queued 325:59
created

Initial_State::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * The React initial state.
4
 *
5
 * @package automattic/jetpack-connection-ui
6
 */
7
8
namespace Automattic\Jetpack\ConnectionUI;
9
10
use Automattic\Jetpack\Connection\Manager;
11
use Automattic\Jetpack\Connection\REST_Connector;
12
13
/**
14
 * The React initial state.
15
 */
16
class Initial_State {
17
18
	/**
19
	 * The connection manager object.
20
	 *
21
	 * @var Manager
22
	 */
23
	private $manager;
24
25
	/**
26
	 * The constructor.
27
	 */
28
	public function __construct() {
29
		$this->manager = new Manager();
30
	}
31
32
	/**
33
	 * Get the initial state data.
34
	 *
35
	 * @return array
36
	 */
37
	private function get_data() {
38
		return array(
39
			'connectionStatus' => REST_Connector::connection_status( false ),
40
		);
41
	}
42
43
	/**
44
	 * Render the initial state into a JavaScript variable.
45
	 *
46
	 * @return string
47
	 */
48
	public function render() {
49
		return 'var CUI_INITIAL_STATE=JSON.parse(decodeURIComponent("' . rawurlencode( wp_json_encode( $this->get_data() ) ) . '"));';
50
	}
51
52
}
53