ScriptNodeBuilder   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 0 Features 1
Metric Value
wmc 4
eloc 5
c 4
b 0
f 1
dl 0
loc 39
ccs 8
cts 8
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getListenNode() 0 3 1
A getChannelContextNode() 0 3 1
A getRootEchoNode() 0 3 1
A getPrivateChannelNode() 0 3 1
1
<?php
2
3
namespace MallardDuck\DynamicEcho\ScriptGenerator;
4
5
use MallardDuck\DynamicEcho\ScriptGenerator\Nodes\ChannelContextNode;
6
use MallardDuck\DynamicEcho\ScriptGenerator\Nodes\ListenNode;
7
use MallardDuck\DynamicEcho\ScriptGenerator\Nodes\PrivateChannelNode;
8
use MallardDuck\DynamicEcho\ScriptGenerator\Nodes\RootEchoNode;
9
10
class ScriptNodeBuilder
11
{
12
    /**
13
     * @return RootEchoNode
14
     */
15 8
    public static function getRootEchoNode(): RootEchoNode
16
    {
17 8
        return new RootEchoNode();
18
    }
19
20
    /**
21
     * Builds a private Echo channel.
22
     *
23
     * @param string $channelIdentifier The name of the echo event channel.
24
     *
25
     * @return PrivateChannelNode
26
     */
27 3
    public static function getPrivateChannelNode(string $channelIdentifier): PrivateChannelNode
28
    {
29 3
        return new PrivateChannelNode($channelIdentifier);
30
    }
31
32
    /**
33
     * Builds a private Echo channel.
34
     *
35
     * @param string $eventName The name of the echo event.
36
     *
37
     * @param string $callback  A javascript event callback used as the listener.
38
     *
39
     * @return ListenNode
40
     */
41 2
    public static function getListenNode(string $eventName, string $callback): ListenNode
42
    {
43 2
        return new ListenNode($eventName, $callback);
44
    }
45
46 3
    public static function getChannelContextNode(string $getChannelJsVarKey, array $channelContext)
47
    {
48 3
        return new ChannelContextNode($getChannelJsVarKey, $channelContext);
49
    }
50
}
51