OnlyValueObjectInterfaceSupportException   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 1
Metric Value
eloc 8
c 1
b 1
f 1
dl 0
loc 20
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A getFieldName() 0 3 1
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