FilterProcessor::__invoke()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
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