Completed
Push — odev ( a25a56...21e788 )
by De Cramer
02:29
created

ChatOutput   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 134
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 94.29%

Importance

Changes 0
Metric Value
wmc 15
lcom 1
cbo 1
dl 0
loc 134
ccs 33
cts 35
cp 0.9429
rs 10
c 0
b 0
f 0

15 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A setLogin() 0 4 1
A setFormatter() 0 3 1
A getChatNotification() 0 4 1
A write() 0 4 1
A writeln() 0 4 1
A setVerbosity() 0 4 1
A getVerbosity() 0 4 1
A isQuiet() 0 4 1
A isVerbose() 0 4 1
A isVeryVerbose() 0 4 1
A isDebug() 0 4 1
A setDecorated() 0 3 1
A isDecorated() 0 4 1
A getFormatter() 0 4 1
1
<?php
2
3
namespace eXpansion\Framework\Core\Helpers;
4
5
use eXpansion\Framework\Core\Model\Helpers\ChatNotificationInterface;
6
use Maniaplanet\DedicatedServer\Connection;
7
use Symfony\Component\Console\Formatter\OutputFormatterInterface;
8
use Symfony\Component\Console\Output\OutputInterface;
9
10
11
/**
12
 * Class ChatOutput can be used to redirect default symfony output to the maniaplanet in game chat.
13
 *
14
 * @package eXpansion\Framework\Core\Helpers;
15
 * @author oliver de Cramer <[email protected]>
16
 */
17
class ChatOutput implements OutputInterface
18
{
19
    /** @var Connection */
20
    protected $connection;
21
22
    /** @var ChatNotificationInterface */
23
    protected $chatNotification;
24
25
    protected $login;
26
27
    /**
28
     * ChatOutput constructor.
29
     *
30
     * @param Connection $connection
31
     * @param ChatNotificationInterface $chatNotification
32
     */
33 14
    public function __construct(Connection $connection, ChatNotificationInterface $chatNotification)
34
    {
35 14
        $this->connection = $connection;
36 14
        $this->chatNotification = $chatNotification;
37 14
    }
38
39
    /**
40
     * @return ChatNotification
41
     */
42 3
    public function getChatNotification()
43
    {
44 3
        return $this->chatNotification;
45
    }
46
47
    /**
48
     * Login to send messages to.
49
     *
50
     * @param mixed $login
51
     */
52 2
    public function setLogin($login)
53
    {
54 2
        $this->login = $login;
55 2
    }
56
57
    /**
58
     * @inheritdoc
59
     */
60 1
    public function write($messages, $newline = false, $options = 0)
61
    {
62 1
        $this->writeln($messages, $options);
63 1
    }
64
65
    /**
66
     * @inheritdoc
67
     */
68 1
    public function writeln($messages, $options = 0)
69
    {
70 1
        $this->connection->chatSendServerMessage(strip_tags($messages), $this->login);
71 1
    }
72
73
    /**
74
     * @inheritdoc
75
     */
76 1
    public function setVerbosity($level)
77
    {
78
        // Nothing to do.
79 1
    }
80
81
    /**
82
     * @inheritdoc
83
     */
84 1
    public function getVerbosity()
85
    {
86 1
        return 0;
87
    }
88
89
    /**
90
     * @inheritdoc
91
     */
92 1
    public function isQuiet()
93
    {
94 1
        return false;
95
    }
96
97
    /**
98
     * @inheritdoc
99
     */
100 1
    public function isVerbose()
101
    {
102 1
        return false;
103
    }
104
105
    /**
106
     * @inheritdoc
107
     */
108 1
    public function isVeryVerbose()
109
    {
110 1
        return false;
111
    }
112
113
    /**
114
     * @inheritdoc
115
     */
116 1
    public function isDebug()
117
    {
118 1
        return false;
119
    }
120
121
    /**
122
     * @inheritdoc
123
     */
124 1
    public function setDecorated($decorated)
125
    {
126 1
    }
127
128
    /**
129
     * @inheritdoc
130
     */
131 1
    public function isDecorated()
132
    {
133 1
        return true;
134
    }
135
136
    /**
137
     * @inheritdoc
138
     */
139
    public function setFormatter(OutputFormatterInterface $formatter)
140
    {
141
    }
142
143
    /**
144
     * @inheritdoc
145
     */
146 1
    public function getFormatter()
147
    {
148 1
        return null;
149
    }
150
}
151