FilterProcessor   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 41
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A filterValue() 0 4 2
A __invoke() 0 4 1
1
<?php
2
/*
3
 * This file is part of Monolog Extensions
4
 *
5
 * Copyright (c) 2014 Nature Delivered Ltd. <http://graze.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @see  http://github.com/graze/MonologExtensions/blob/master/LICENSE
11
 * @link http://github.com/graze/MonologExtensions
12
 */
13
14
namespace Graze\Monolog\Processor;
15
16
class FilterProcessor
17
{
18
    /**
19
     * @var array
20
     */
21
    protected $keys;
22
23
    /**
24
     * @var string
25
     */
26
    protected $replacement;
27
28
    /**
29
     * @param array  $keys
30
     * @param string $replacement
31
     */
32 4
    public function __construct(array $keys = [], $replacement = null)
33
    {
34 4
        $this->keys = $keys;
35 4
        $this->replacement = $replacement;
36 4
    }
37
38
    /**
39
     * @param array $record
40
     *
41
     * @return array
42
     */
43 3
    public function __invoke(array $record)
44
    {
45 3
        array_walk_recursive($record, [$this, 'filterValue']);
46 3
        return $record;
47
    }
48
49
    /**
50
     * @param mixed  $value Value to filter as reference
51
     * @param string $key
52
     */
53 3
    protected function filterValue(&$value, $key)
54
    {
55 3
        if (in_array($key, $this->keys, true)) {
56 3
            $value = $this->replacement;
57
        }
58 3
    }
59
}
60