DevModeNotifier   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 66
ccs 0
cts 28
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A onPreLoop() 0 4 1
A onPostLoop() 0 4 1
A onEverySecond() 0 17 2
1
<?php
2
3
4
namespace eXpansion\Framework\Core\Plugins;
5
use eXpansion\Framework\Core\DataProviders\Listener\ListenerInterfaceExpTimer;
6
use eXpansion\Framework\Core\Helpers\ChatNotification;
7
use eXpansion\Framework\Core\Services\Console;
8
9
10
/**
11
 * Class DevModeNotifier
12
 *
13
 * @package eXpansion\Framework\Core\Plugins;
14
 * @author  oliver de Cramer <[email protected]>
15
 */
16
class DevModeNotifier implements ListenerInterfaceExpTimer
17
{
18
    /** @var ChatNotification */
19
    protected $chatNotification;
20
21
    /** @var Console */
22
    protected $console;
23
24
    /** @var int How often notificaiton needs to be displayed */
25
    protected $interval = 300;
26
27
    /** @var int last time it was displayed. */
28
    protected $lastDisplayTime;
29
30
    /**
31
     * DevModeNotifier constructor.
32
     *
33
     * @param ChatNotification $chatNotification
34
     * @param Console         $console
35
     */
36
    public function __construct(ChatNotification $chatNotification, Console $console)
37
    {
38
        $this->chatNotification = $chatNotification;
39
        $this->console = $console;
40
41
        // Display once 30 seconds after start.
42
        $this->lastDisplayTime = time() - $this->interval + 10;
43
    }
44
45
    /**
46
     * @inheritdoc
47
     */
48
    public function onPreLoop()
49
    {
50
        // nothing
51
    }
52
53
    /**
54
     * @inheritdoc
55
     */
56
    public function onPostLoop()
57
    {
58
        // nothing
59
    }
60
61
    /**
62
     * @inheritdoc
63
     */
64
    public function onEverySecond()
65
    {
66
        if (time() > $this->lastDisplayTime + $this->interval) {
67
            $this->lastDisplayTime = time();
68
69
            $this->console->getSfStyleOutput()->warning(
70
                [
71
                    "!! eXpansion is running in dev mode !!",
72
                    "In dev mode eXpansion is not stable and will leak memory which will cause crash.",
73
                    "This is normal behaviour. Please use prod mode. ",
74
                    "",
75
                    "If you are currently developing please ignore this message.",
76
                ]
77
            );
78
            $this->chatNotification->sendMessage("{warning} eXpansion is in dev mode. Memory leaks are normal.");
79
        }
80
    }
81
}