Boolean   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 1
Metric Value
eloc 14
c 1
b 1
f 1
dl 0
loc 51
rs 10
wmc 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A supportsFromNative() 0 3 1
A fromNative() 0 3 1
A toNative() 0 6 2
A __toString() 0 3 1
A __construct() 0 3 1
A supportsToNative() 0 3 1
A supports() 0 6 2
A fromMissingValue() 0 3 1
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 Boolean implements TypeUtilInterface
10
{
11
    /**
12
     * @var string
13
     */
14
    private $fieldName;
15
16
    public function __construct(string $fieldName)
17
    {
18
        $this->fieldName = $fieldName;
19
    }
20
21
    public function fromNative($input)
22
    {
23
        return $this->toNative($input);
24
    }
25
26
    public function toNative($input)
27
    {
28
        if ($input instanceof ValueObjectInterface) {
29
            return !! $input->toNative();
30
        }
31
        return !! $input;
32
    }
33
34
    public function fromMissingValue()
35
    {
36
        throw new MissingValueException($this->fieldName);
37
    }
38
39
    public function supports($input): bool
40
    {
41
        if ($input instanceof ValueObjectInterface) {
42
            return $this->supportsFromNative($input->toNative());
43
        }
44
        return $this->supportsFromNative($input);
45
    }
46
47
    public function supportsToNative($input): bool
48
    {
49
        return gettype($input) === 'boolean';
50
    }
51
52
    public function supportsFromNative($input): bool
53
    {
54
        return $this->supportsToNative($input);
55
    }
56
57
    public function __toString()
58
    {
59
        return 'bool';
60
    }
61
}
62