TransformationNotFound::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 1
nop 3
dl 0
loc 5
rs 10
c 0
b 0
f 0
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