Total Complexity | 7 |
Total Lines | 76 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 2 | ||
Bugs | 0 | Features | 2 |
1 | <?php |
||
18 | class ReactJS { |
||
19 | |||
20 | /** |
||
21 | * |
||
22 | * @var array |
||
23 | */ |
||
24 | private $operations; |
||
25 | |||
26 | public $components; |
||
27 | |||
28 | /** |
||
29 | * |
||
30 | * @var TemplateParser |
||
31 | */ |
||
32 | private $renderTemplate; |
||
33 | |||
34 | /** |
||
35 | * Initialize templates. |
||
36 | */ |
||
37 | 3 | public function __construct() { |
|
43 | 3 | } |
|
44 | |||
45 | /** |
||
46 | * Insert a react component in the DOM. |
||
47 | * |
||
48 | * @param string $jsxHtml |
||
49 | * @param string $selector |
||
50 | * @return string |
||
51 | */ |
||
52 | 3 | public function renderComponent(string $jsxHtml, string $selector): string { |
|
57 | ]); |
||
58 | 3 | })(); |
|
59 | } |
||
60 | |||
61 | /** |
||
62 | * Create and return a new ReactComponent. |
||
63 | * |
||
64 | * @param string $name |
||
65 | * @param bool $compile |
||
66 | * @return ReactComponent |
||
67 | */ |
||
68 | 3 | public function createComponent(string $name, $compile = true): ReactComponent { |
|
69 | 3 | $compo = new ReactComponent($name, $this); |
|
70 | 3 | $this->components[\strtolower($name)] = $name; |
|
71 | 3 | if ($compile) { |
|
72 | 3 | $this->operations[] = function () use ($compo) { |
|
73 | 3 | return $compo->parse(); |
|
74 | }; |
||
75 | } |
||
76 | 3 | return $compo; |
|
77 | } |
||
78 | |||
79 | /** |
||
80 | * Generate the javascript code. |
||
81 | * |
||
82 | * @return string |
||
83 | */ |
||
84 | 3 | public function compile(): string { |
|
90 | } |
||
91 | |||
92 | 2 | public function __toString() { |
|
97 |