DefaultExceptionTransformer::transformException()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 14
ccs 9
cts 9
cp 1
rs 9.4285
cc 2
eloc 8
nc 2
nop 1
crap 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