Completed
Push — master ( a8cb62...764ba2 )
by François
03:52
created

BaseLogger   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
B format() 0 26 6
A formatAddress() 0 10 4
A formatRequest() 0 8 3
1
<?php
2
3
/*
4
 * This file is part of the Bouncer package.
5
 *
6
 * (c) François Hodierne <[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
namespace Bouncer\Logger;
13
14
/**
15
 * Base Logger class providing the Cache structure
16
 *
17
 * @author François Hodierne <[email protected]>
18
 */
19
abstract class BaseLogger
20
{
21
22
    public function format(array $logEntry)
23
    {
24
        $formattedEntry = array();
25
26
        if (isset($logEntry['address'])) {
27
            $formattedEntry['address'] = $this->formatAddress($logEntry['address']);
28
        }
29
30
        if (isset($logEntry['request'])) {
31
            $formattedEntry['request'] = $this->formatRequest($logEntry['request']);
32
        }
33
34
        if (isset($logEntry['response'])) {
35
            $formattedEntry['response'] = $logEntry['response'];
36
        }
37
38
        if (isset($logEntry['context'])) {
39
            $formattedEntry['context']['bouncer'] = $logEntry['context'];
40
        }
41
42
        if (isset($logEntry['key'])) {
43
            $formattedEntry['key'] = $logEntry['key'];
44
        }
45
46
        return $formattedEntry;
47
    }
48
49
    public function formatAddress($address)
50
    {
51
        if (is_object($address)) {
52
            return $address->getValue();
53
        } elseif (is_array($address)) {
54
            return $address['value'];
55
        } elseif (is_string($address)) {
56
            return $address;
57
        }
58
    }
59
60
    public function formatRequest($request)
61
    {
62
        if (is_object($request)) {
63
            return $request->toArray();
64
        } elseif (is_array($request)) {
65
            return $request;
66
        }
67
    }
68
69
}
70