Completed
Push — master ( 758742...ec9771 )
by Zach
02:36
created

Logger   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 4
c 1
b 1
f 0
lcom 1
cbo 1
dl 0
loc 47
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A write() 0 4 1
A getLog() 0 8 2
A hasMessage() 0 4 1
1
<?php
2
3
namespace Yarak\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
        $this->log[] = $message;
22
    }
23
24
    /**
25
     * Return the log array.
26
     *
27
     * @param int $index
28
     *
29
     * @return array
30
     */
31
    public function getLog($index = null)
32
    {
33
        if (is_null($index)) {
34
            return $this->log;
35
        }
36
37
        return $this->log[$index];
38
    }
39
40
    /**
41
     * Return true if log contains message.
42
     *
43
     * @param string $message
44
     *
45
     * @return bool
46
     */
47
    public function hasMessage($message)
48
    {
49
        return in_array($message, $this->getLog());
50
    }
51
}
52