Completed
Push — master ( 4deee6...b383ba )
by Zach
05:43 queued 03:44
created

Logger   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 57
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A write() 0 6 2
A getLog() 0 8 2
A hasMessage() 0 4 1
A clearLog() 0 4 1
1
<?php
2
3
namespace Yarak\Console\Output;
4
5
class Logger extends Output
6
{
7
    /**
8
     * Log of received messages.
9
     *
10
     * @var array
11
     */
12
    protected $log = [];
13
14
    /**
15
     * Write a message.
16
     *
17
     * @param string $message
18
     */
19
    public function write($message)
20
    {
21
        if ($this->verbosity) {
22
            $this->log[] = $message;
23
        }
24
    }
25
26
    /**
27
     * Return the log array.
28
     *
29
     * @param int $index
30
     *
31
     * @return array
32
     */
33
    public function getLog($index = null)
34
    {
35
        if (is_null($index)) {
36
            return $this->log;
37
        }
38
39
        return $this->log[$index];
40
    }
41
42
    /**
43
     * Return true if log contains message.
44
     *
45
     * @param string $message
46
     *
47
     * @return bool
48
     */
49
    public function hasMessage($message)
50
    {
51
        return in_array($message, $this->getLog());
52
    }
53
54
    /**
55
     * Clear the log.
56
     */
57
    public function clearLog()
58
    {
59
        $this->log = [];
60
    }
61
}
62