FormModel::check()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
ccs 0
cts 4
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Anax\HTMLForm;
4
5
use Psr\Container\ContainerInterface;
6
7
/**
8
 * Base class for form model classes.
9
 */
10
abstract class FormModel
11
{
12
    /**
13
     * @var Anax\DI\DIInterface $di   the DI/service container.
0 ignored issues
show
Bug introduced by
The type Anax\HTMLForm\Anax\DI\DIInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
     * @var class               $form the main form class.
15
     */
16
    protected $di;
17
    protected $form;
18
19
20
21
    /**
22
     * Constructor injects with DI container and creates the form.
23
     *
24
     * @param Psr\Container\ContainerInterface $di a service container
0 ignored issues
show
Bug introduced by
The type Anax\HTMLForm\Psr\Container\ContainerInterface was not found. Did you mean Psr\Container\ContainerInterface? If so, make sure to prefix the type with \.
Loading history...
25
     */
26
    public function __construct(ContainerInterface $di)
27
    {
28
        $this->di = $di;
0 ignored issues
show
Documentation Bug introduced by
It seems like $di of type Psr\Container\ContainerInterface is incompatible with the declared type Anax\HTMLForm\Anax\DI\DIInterface of property $di.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
29
        $this->form = new Form($di);
30
    }
31
32
33
34
    /**
35
     * Customise the check() method to use own methods.
36
     *
37
     * @return boolean|null $callbackStatus if submitted&validates, false if
38
     *                                      not validate, null if not submitted.
39
     *                                      If submitted the callback function
40
     *                                      will return the actual value which
41
     *                                      should be true or false.
42
     */
43
    public function check()
44
    {
45
        return $this->form->check(
46
            [$this, "callbackSuccess"],
47
            [$this, "callbackFail"]
48
        );
49
    }
50
51
52
53
    /**
54
     * Return HTML for the form.
55
     *
56
     * @param array $options with options affecting the form output.
57
     *
58
     * @return string with HTML for the form.
59
     */
60
    public function getHTML($options = [])
61
    {
62
        return $this->form->getHTML($options);
63
    }
64
65
66
67
    /**
68
     * Callback what to do if the form was successfully submitted, this
69
     * happen when the submit callback method returns true. This method
70
     * can/should be implemented by the subclass for a different behaviour.
71
     */
72
    public function callbackSuccess()
73
    {
74
        $this->di->get("response")->redirectSelf()->send();
75
    }
76
77
78
79
    /**
80
     * Callback what to do if the form was unsuccessfully submitted, this
81
     * happen when the submit callback method returns false or if validation
82
     * fails. This method can/should be implemented by the subclass for a
83
     * different behaviour.
84
     */
85
    public function callbackFail()
86
    {
87
        $this->di->get("response")->redirectSelf()->send();
88
    }
89
}
90