DefaultExceptionTransformer   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 34
ccs 12
cts 12
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A transformException() 0 14 2
1
<?php
2
3
namespace Alchemy\Rest\Response\ExceptionTransformer;
4
5
use Alchemy\Rest\Response\ExceptionTransformer;
6
7
class DefaultExceptionTransformer implements ExceptionTransformer
8
{
9
    /**
10
     * @var bool
11
     */
12
    private $debug;
13
14
    /**
15
     * @param bool $debug
16
     */
17 4
    public function __construct($debug = false)
18
    {
19 4
        $this->debug = (bool) $debug;
20 4
    }
21
22
    /**
23
     * @param \Exception $exception
24
     * @return array
25
     */
26 4
    public function transformException(\Exception $exception)
27
    {
28
        $data = array(
29 4
            'code' => $exception->getCode(),
30 4
            'message' => $exception->getMessage()
31 4
        );
32
33 4
        if ($this->debug === true) {
34 2
            $data['exception'] = get_class($exception);
35 2
            $data['trace'] = $exception->getTraceAsString();
36 2
        }
37
38 4
        return array('error' => $data);
39
    }
40
}
41