Completed
Push — master ( a68940...ed2b3e )
by Mikael
02:38
created

FormModelCheckboxMultiple::callbackSubmitFail()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
ccs 0
cts 4
cp 0
crap 2
1
<?php
2
3
namespace Anax\HTMLForm;
4
5
use Anax\DI\DIInterface;
6
7
/**
8
 * Example of FormModel implementation.
9
 */
10
class FormModelCheckboxMultiple extends FormModel
11
{
12
    /**
13
     * Constructor injects with DI container.
14
     *
15
     * @param Anax\DI\DIInterface $di a service container
16
     */
17
    public function __construct(DIInterface $di)
18
    {
19
        parent::__construct($di);
20
        $this->form->create(
21
            [
22
                "id" => __CLASS__,
23
                "legend" => "Legend"
24
            ],
25
            [
26
                "items" => [
27
                    "type"        => "checkbox-multiple",
28
                    "values"      => ["tomato", "potato", "apple", "pear", "banana"],
29
                    "checked"     => ["potato", "pear"],
30
                ],
31
                "submit" => [
32
                    "type"      => "submit",
33
                    "callback"  => [$this, "callbackSubmit"],
34
                ],
35
            ]
36
        );
37
    }
38
39
40
41
    /**
42
     * Callback for submit-button which should return true if it could
43
     * carry out its work and false if something failed.
44
     *
45
     * @return boolean true if okey, false if something went wrong.
46
     */
47 View Code Duplication
    public function callbackSubmit()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
48
    {
49
        // Get the selected items as an array
50
        $items = $this->form->value("items");
51
52
        // Print output for sake of this example
53
        $this->form->addOutput(
54
            "<p>Selected items are: '"
55
            . implode(", ", $items)
56
            . "'."
57
        );
58
59
        // Remember values during resubmit, for sake of the example
60
        $this->form->rememberValues();
61
62
        return true;
63
    }
64
}
65