MixedTypehint::fromNative()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 1
Metric Value
cc 2
eloc 3
c 1
b 1
f 1
nc 2
nop 1
dl 0
loc 6
rs 10
1
<?php
2
3
4
namespace Apie\TypeJuggling;
5
6
use Apie\TypeJuggling\Exceptions\MissingValueException;
7
use Apie\ValueObjects\ValueObjectInterface;
0 ignored issues
show
Bug introduced by
The type Apie\ValueObjects\ValueObjectInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
9
class MixedTypehint extends Compound
10
{
11
    private $fieldName;
12
13
    public function __construct(string $fieldName)
14
    {
15
        $this->fieldName = $fieldName;
16
        parent::__construct(
17
            $fieldName,
18
            new Boolean($fieldName),
19
            new FloatingPoint($fieldName),
20
            new Integer($fieldName),
21
            new StringLiteral($fieldName),
22
            new PrimitiveArray($fieldName),
23
            new NullObject()
24
        );
25
    }
26
27
    public function fromMissingValue()
28
    {
29
        throw new MissingValueException($this->fieldName);
30
    }
31
32
    public function supports($input): bool
33
    {
34
        return ($input instanceof ValueObjectInterface) || parent::supports($input);
35
    }
36
37
    public function supportsFromNative($input): bool
38
    {
39
        return ($input instanceof ValueObjectInterface) || parent::supportsFromNative($input);
40
    }
41
42
    public function supportsToNative($input): bool
43
    {
44
        return ($input instanceof ValueObjectInterface) || parent::supportsToNative($input);
45
    }
46
47
    public function fromNative($input)
48
    {
49
        if ($input instanceof ValueObjectInterface) {
50
            return $input;
51
        }
52
        return parent::fromNative($input);
53
    }
54
55
    public function toNative($input)
56
    {
57
        if ($input instanceof ValueObjectInterface) {
58
            return $input->toNative();
59
        }
60
        return parent::toNative($input);
61
    }
62
63
    public function __toString()
64
    {
65
        return 'mixed';
66
    }
67
}
68