AbstractLog   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 97
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 97
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 3

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getWriterKey() 0 7 2
A setWriterKey() 0 5 1
A filterPriority() 0 5 1
A filterRegex() 0 5 1
A setProcessor() 0 13 1
A toArray() 0 12 1
1
<?php
2
/**
3
 * Webino™ (http://webino.sk)
4
 *
5
 * @link        https://github.com/webino for the canonical source repository
6
 * @copyright   Copyright (c) 2015-2017 Webino, s.r.o. (http://webino.sk)
7
 * @author      Peter Bačinský <[email protected]>
8
 * @license     BSD-3-Clause
9
 */
10
11
namespace WebinoConfigLib\Feature;
12
13
use WebinoConfigLib\Log\Writer;
14
use WebinoLogLib\SeverityInterface;
15
16
/**
17
 * Class AbstractLog
18
 */
19
abstract class AbstractLog extends AbstractFeature implements
20
    SeverityInterface
21
{
22
    /**
23
     * Application configuration key
24
     */
25
    const KEY = 'log';
26
27
    /**
28
     * @var Writer\AbstractWriter
29
     */
30
    protected $writer;
31
32
    /**
33
     * @var string
34
     */
35
    protected $writerKey;
36
37
    /**
38
     * @return string
39
     */
40
    protected function getWriterKey()
41
    {
42
        if (null === $this->writerKey) {
43
            $this->setWriterKey(get_class($this));
44
        }
45
        return $this->writerKey;
46
    }
47
48
    /**
49
     * @param string $key
50
     * @return $this
51
     */
52
    protected function setWriterKey($key)
53
    {
54
        $this->writerKey = (string) $key;
55
        return $this;
56
    }
57
58
    /**
59
     * Set priority to filter log messages
60
     *
61
     * @param int $priority
62
     * @return $this
63
     */
64
    public function filterPriority($priority)
65
    {
66
        $this->writer->setFilter('priority', ['priority' => $priority]);
67
        return $this;
68
    }
69
70
    /**
71
     * Set regular expression to filter log messages
72
     *
73
     * @param int $regex
74
     * @return $this
75
     */
76
    public function filterRegex($regex)
77
    {
78
        $this->writer->setFilter('regex', ['regex' => $regex]);
79
        return $this;
80
    }
81
82
    /**
83
     * @param string $name
84
     * @param array $options
85
     */
86
    protected function setProcessor($name, array $options = [])
87
    {
88
        $this->mergeArray([
89
            $this::KEY => [
90
                'processors' => [
91
                    $name => [
92
                        'name'    => $name,
93
                        'options' => $options,
94
                    ],
95
                ],
96
            ]
97
        ]);
98
    }
99
100
    /**
101
     * @return array
102
     */
103
    public function toArray()
104
    {
105
        $this->setProcessor('psrplaceholder');
106
107
        $this->mergeArray([
108
            $this::KEY => (new Writer([
109
                $this->getWriterKey() => $this->writer->toArray(),
110
            ]))->toArray(),
111
        ]);
112
113
        return parent::toArray();
114
    }
115
}
116