getFieldName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 1
Metric Value
cc 1
eloc 1
c 1
b 1
f 1
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
4
namespace Apie\TypeJuggling\Exceptions;
5
6
use Apie\Core\Exceptions\ApieException;
7
use Apie\Core\Exceptions\FieldNameAwareInterface;
8
9
/**
10
 * Exception thrown if a wrong type is sent to fromNative that is not supported, for
11
 * example resources or any arbitrary class.
12
 */
13
class OnlyValueObjectInterfaceSupportException extends ApieException implements FieldNameAwareInterface
14
{
15
    private $fieldName;
16
17
    public function __construct(string $fieldName, ?string $className)
18
    {
19
        $this->fieldName = $fieldName;
20
        $message = 'Typehint object on field "' . $fieldName . '" is not supported';
21
        if ($className !== null) {
22
            $message = 'Class ' . $className . ' found on field "' . $fieldName . '" is not implementing ValueObjectInterface and is not supported';
23
        }
24
        parent::__construct(422, $message);
25
    }
26
27
    /**
28
     * @return string
29
     */
30
    public function getFieldName(): string
31
    {
32
        return $this->fieldName;
33
    }
34
}
35