ChannelContextNode   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 86.67%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 14
c 1
b 0
f 0
dl 0
loc 28
ccs 13
cts 15
cp 0.8667
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __toString() 0 12 3
A __construct() 0 4 1
A jsonSerialize() 0 3 1
1
<?php
2
3
namespace MallardDuck\DynamicEcho\ScriptGenerator\Nodes;
4
5
class ChannelContextNode extends ContextNode
6
{
7
    public string $channelJsVarKey;
8
    public array $channelContext;
9
10 3
    public function __construct(string $channelJsVarKey, array $channelContext)
11
    {
12 3
        $this->channelJsVarKey = $channelJsVarKey;
13 3
        $this->channelContext = $channelContext;
14 3
    }
15
16 1
    public function __toString()
17
    {
18 1
        $res = "";
19 1
        $count = count($this->channelContext);
20 1
        foreach ($this->channelContext as $key => $value) {
21 1
            --$count;
22 1
            $res .= sprintf("%s: %s", $key, $value);
23 1
            if ($count >= 1) {
24 1
                $res .= ",\r\n";
25
            }
26
        }
27 1
        return sprintf("%s: {%s}", $this->channelJsVarKey, $res);
28
    }
29
30
    public function jsonSerialize()
31
    {
32
        return json_encode([$this->channelJsVarKey => $this->channelContext]);
33
    }
34
}
35