BaseLogger   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 14
lcom 0
cbo 0
dl 0
loc 55
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
C format() 0 30 7
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'] = $logEntry['context'];
40
        }
41
42
        if (isset($logEntry['key'])) {
43
            $formattedEntry['key'] = $logEntry['key'];
44
        }
45
46
        if (isset($logEntry['session'])) {
47
            $formattedEntry['session'] = $logEntry['session'];
48
        }
49
50
        return $formattedEntry;
51
    }
52
53
    public function formatAddress($address)
54
    {
55
        if (is_object($address)) {
56
            return $address->getValue();
57
        } elseif (is_array($address)) {
58
            return $address['value'];
59
        } elseif (is_string($address)) {
60
            return $address;
61
        }
62
    }
63
64
    public function formatRequest($request)
65
    {
66
        if (is_object($request)) {
67
            return $request->toArray();
68
        } elseif (is_array($request)) {
69
            return $request;
70
        }
71
    }
72
73
}
74