ArrayLogger   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 10
eloc 15
c 0
b 0
f 0
dl 0
loc 53
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A clear() 0 3 1
A count() 0 3 1
A getLogs() 0 3 1
A __construct() 0 4 1
A log() 0 10 6
1
<?php
2
3
/**
4
 * This file is part of the Lazzard/ftp-bridge package.
5
 *
6
 * (c) El Amrani Chakir <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 */
12
13
namespace Lazzard\FtpBridge\Logger;
14
15
/**
16
 * ArrayLogger
17
 *
18
 * @since  1.0
19
 * @author El Amrani Chakir <[email protected]>
20
 */
21
class ArrayLogger extends Logger
22
{
23
    /** @var array */
24
    protected $logs;
25
26
    /**
27
     * @param int $mode
28
     */
29
    public function __construct($mode = LoggerInterface::PLAIN_MODE)
30
    {
31
        parent::__construct($mode);
32
        $this->logs = array();
33
    }
34
35
    /**
36
     * @return array
37
     */
38
    public function getLogs()
39
    {
40
        return $this->logs;
41
    }
42
43
    /**
44
     * @inheritDoc
45
     */
46
    public function log($level, $message)
47
    {
48
        if ($this->mode === self::PLAIN_MODE) {
49
            $this->logs[] = sprintf("%s %s", $level, $message);
50
        } elseif ($this->mode === self::ARRAY_MODE) {
51
            $lines = explode(self::CRLF, $message);
52
            $this->logs[] = sprintf("%s %s", $level, $lines[0]);
53
            foreach ($lines as $key => $line) {
54
                if ($key === 0 || $line === '') continue;
55
                $this->logs[] = $line;
56
            }
57
        }
58
    }
59
60
    /**
61
     * @inheritDoc
62
     */
63
    public function clear()
64
    {
65
        $this->logs = [];
66
    }
67
68
    /**
69
     * @inheritDoc
70
     */
71
    public function count()
72
    {
73
        return count($this->logs);
74
    }
75
}