Passed
Push — master ( 548923...89935f )
by Thierry
08:39
created

DataBag::__construct()   A

Complexity

Conditions 5
Paths 3

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 13
rs 9.6111
cc 5
nc 3
nop 0
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace Jaxon\Response\Plugin;
4
5
use function is_array;
6
7
class DataBag extends \Jaxon\Plugin\Response
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class DataBag
Loading history...
8
{
9
    /**
10
     * @var DataBag\Bag
11
     */
12
    protected $xBag;
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line(s) before first member var; 0 found
Loading history...
13
14
    /**
15
     * The constructor
16
     */
17
    public function __construct()
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
18
    {
19
        // Todo: clean input data.
20
        $aData = [];
21
        if(isset($_POST['jxnbags']) && is_array($_POST['jxnbags']))
22
        {
23
            $aData = $_POST['jxnbags'];
24
        }
25
        elseif(isset($_GET['jxnbags']) && is_array($_GET['jxnbags']))
26
        {
27
            $aData = $_GET['jxnbags'];
28
        }
29
        $this->xBag = new DataBag\Bag($aData);
30
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
31
32
    /**
33
     * @inheritDoc
34
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
35
    public function getName()
36
    {
37
        return 'bags';
38
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
39
40
    /**
41
     * @inheritDoc
42
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
43
    public function getHash()
44
    {
45
        // Use the version number as hash
46
        return '1.0.0';
47
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
48
49
    /**
50
     * @inheritDoc
51
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
52
    public function getReadyScript()
53
    {
54
        return '
55
    jaxon.command.handler.register("bags.set", function(args) {
56
        for (const bag in args.data) {
57
            jaxon.ajax.parameters.bags[bag] = args.data[bag];
58
        }
59
    });
60
';
61
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
62
63
    /**
64
     * @return bool
65
     */
66
    public function writeCommand()
67
    {
68
        if($this->xBag->touched())
69
        {
70
            $this->addCommand(['cmd' => 'bags.set'], $this->xBag->getAll());
0 ignored issues
show
Bug introduced by
$this->xBag->getAll() of type array is incompatible with the type string expected by parameter $sData of Jaxon\Plugin\Response::addCommand(). ( Ignorable by Annotation )

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

70
            $this->addCommand(['cmd' => 'bags.set'], /** @scrutinizer ignore-type */ $this->xBag->getAll());
Loading history...
71
        }
72
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
73
74
    /**
75
     * @param string $sName
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
76
     *
77
     * @return DataBag\Bag
78
     */
79
    public function bag($sName)
80
    {
81
        return $this->xBag->setName($sName);
82
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
83
}
84