Passed
Push — main ( 83e3d1...e51278 )
by Jean-Christophe
02:23
created

ReactComponent::onComponentWillUnmount()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 2
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
namespace PHPMV\react;
3
4
use PHPMV\core\ReactClass;
5
use PHPMV\utils\JSX;
6
7
/**
8
 * A React component generator.
9
 * PHPMV\react$ReactComponent
10
 * This class is part of php-react
11
 *
12
 * @author jc
13
 * @version 1.0.0
14
 *
15
 */
16
class ReactComponent extends ReactClass {
17
18
	private $react;
19
20 1
	public function __construct(string $name, ReactJS $react) {
21 1
		parent::__construct($name, 'React.Component');
22 1
		$this->react = $react;
23 1
	}
24
25
	/**
26
	 * Add the constructor.
27
	 *
28
	 * @param string $jsBody
29
	 *        	The Javascript code body
30
	 */
31 1
	public function addConstructor(string $jsBody): void {
32 1
		$this->addMethod('constructor', "\tsuper(props);\n" . $jsBody, 'props');
33 1
	}
34
35
	/**
36
	 * Add the render method.
37
	 *
38
	 * @param string $jsxHtml
39
	 *        	The JSX code to render
40
	 * @param string $jsInit
41
	 *        	Javascript code intialization before render
42
	 */
43 1
	public function addRender(string $jsxHtml, string $jsInit = ''): void {
44 1
		$this->addMethod('render', $jsInit . ";return " . JSX::toJs($jsxHtml, $this->react) . ";");
45 1
	}
46
47
	/**
48
	 * Add the componentDidMount method.
49
	 *
50
	 * @param string $jsBody
51
	 *        	The Javascript code body
52
	 */
53
	public function onComponentDidMount(string $jsBody): void {
54
		$this->addMethod('componentDidMount', $jsBody);
55
	}
56
57
	/**
58
	 * Add the componentWillUnmount method.
59
	 *
60
	 * @param string $jsBody
61
	 *        	The Javascript code body
62
	 */
63
	public function onComponentWillUnmount(string $jsBody): void {
64
		$this->addMethod('componentWillUnmount', $jsBody);
65
	}
66
67
	public function setState(array $states) {}
1 ignored issue
show
Unused Code introduced by
The parameter $states is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

67
	public function setState(/** @scrutinizer ignore-unused */ array $states) {}

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
68
}
69
70