TransformationNotFound   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 37
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getData() 0 3 1
A formatMessage() 0 5 2
A __construct() 0 5 2
1
<?php
2
3
/*
4
 * This file is part of the ICanBoogie package.
5
 *
6
 * (c) Olivier Laviale <[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 ICanBoogie\Transformation;
13
14
/**
15
 * Exception throws when a transformation cannot be found to transform data.
16
 */
17
class TransformationNotFound extends \LogicException implements Exception
18
{
19
    /**
20
     * @var mixed
21
     */
22
    private $data;
23
24
    /**
25
     * @return mixed
26
     */
27
    public function getData()
28
    {
29
        return $this->data;
30
    }
31
32
    /**
33
     * @param mixed $data
34
     * @param string|null $message
35
     * @param \Throwable|null $previous
36
     */
37
    public function __construct($data, string $message = null, \Throwable $previous = null)
38
    {
39
        $this->data = $data;
40
41
        parent::__construct($message ?: $this->formatMessage($data), 0, $previous);
42
    }
43
44
    /**
45
     * @param mixed $data
46
     *
47
     * @return string
48
     */
49
    private function formatMessage($data): string
50
    {
51
        $type = is_object($data) ? "instance of " . get_class($data) : "type " . gettype($data);
52
53
        return "Transformation not found for $type.";
54
    }
55
}
56