Test Failed
Push — master ( 194522...eda1b6 )
by Mikael
01:43
created

FormModel   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 44
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A check() 0 4 1
callbackSubmit() 0 1 ?
A callbackSuccess() 0 6 1
A callbackFail() 0 6 1
1
<?php
2
3
namespace Anax\HTMLForm;
4
5
/**
6
 * Base class for form model classes.
7
 *
8
 */
9
abstract class FormModel extends Form
10
{
11
    /**
12
     * Customise the check() method to use own methods.
13
     *
14
     * @param callable $callIfSuccess handler to call if function returns true.
15
     * @param callable $callIfFail    handler to call if function returns true.
16
     */
17
    public function check($callIfSuccess = null, $callIfFail = null)
18
    {
19
        return parent::check([$this, "callbackSuccess"], [$this, "callbackFail"]);
20
    }
21
22
23
24
    /**
25
     * Callback for submitting the form.
26
     */
27
    abstract public function callbackSubmit();
28
29
30
31
    /**
32
     * Callback What to do if the form was submitted successfully?
33
     */
34
    public function callbackSuccess()
35
    {
36
        $this->AddOUtput("<p>#callbackSuccess()</p>");
37
        $this->AddOUtput("<p>Form was submitted and the callback method returned true.</p>");
38
        header("Location: " . $_SERVER['PHP_SELF']);
39
    }
40
41
42
43
    /**
44
     * Callback What to do when submitted form could not be processed?
45
     */
46
    public function callbackFail()
47
    {
48
        $this->AddOutput("<p>#callbackFailed()</p>");
49
        $this->AddOutput("<p>Form was submitted and the Check() method returned false.</p>");
50
        header("Location: " . $_SERVER['PHP_SELF']);
51
    }
52
}
53