FormPrinterHandler::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 4
cts 4
cp 1
rs 10
cc 1
eloc 3
nc 1
nop 2
crap 1
1
<?php
2
3
namespace SES;
4
5
use Title;
6
7
/**
8
 * @license GNU GPL v2+
9
 * @since 1.1
10
 *
11
 * @author mwjames
12
 */
13
class FormPrinterHandler {
14
15
	/**
16
	 * @var Title|null
17
	 */
18
	private $form;
19
20
	/**
21
	 * @var mixed
22
	 */
23
	private $formPrinter;
24
25
	/**
26
	 * @var string
27
	 */
28
	private $formText = '';
29
30
	/**
31
	 * @var string
32
	 */
33
	private $dataText = '';
34
35
	/**
36
	 * @var boolean
37
	 */
38
	private $submitState = false;
39
40
	/**
41
	 * @since 1.1
42
	 */
43 4
	public function __construct( Title $form = null, $formPrinter = null ) {
44 4
		$this->form = $form;
45 4
		$this->formPrinter = $formPrinter;
46 4
	}
47
48
	/**
49
	 * @since 1.1
50
	 *
51
	 * @return boolean
52
	 */
53 3
	public function canUseForm() {
54 3
		return $this->form !== null && $this->form->exists();
55
	}
56
57
	/**
58
	 * @since 1.1
59
	 *
60
	 * @param boolean $submitState
61
	 */
62
	public function setSubmitState( $submitState ) {
63
		$this->submitState = $submitState;
64
	}
65
66
	/**
67
	 * @since 1.1
68
	 *
69
	 * @return string
70
	 */
71 1
	public function getFormText() {
72
73 1
		if ( $this->formText === '' ) {
74 1
			$this->createForm();
75 1
		}
76
77 1
		return $this->formText;
78
	}
79
80
	/**
81
	 * @since 1.1
82
	 *
83
	 * @return string
84
	 */
85 1
	public function getTemplateText() {
86
87 1
		if ( $this->dataText === '' ) {
88 1
			$this->createForm();
89 1
		}
90
91 1
		return $this->dataText;
92
	}
93
94 2
	private function createForm() {
95
96 2
		if ( !$this->canUseForm() || !is_object( $this->formPrinter ) ) {
97 2
			return;
98
		}
99
100 2
		$form = new \Article( $this->form );
101 2
		$form_definition = $form->getContent();
102
103
		list ( $form_text, $javascript_text, $data_text, $form_page_title, $generated_page_name ) =
0 ignored issues
show
Unused Code introduced by
The assignment to $javascript_text is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
Unused Code introduced by
The assignment to $form_page_title is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
Unused Code introduced by
The assignment to $generated_page_name is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
104 2
			$this->formPrinter->formHTML( $form_definition, $this->submitState, false );
105
106 2
		$this->formText = $form_text;
107 2
		$this->dataText = $data_text;
108 2
	}
109
110
}
111