Passed
Push — master ( 33e582...680f77 )
by Mr
02:06
created

NullValue   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 85.71%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
dl 0
loc 35
ccs 12
cts 14
cp 0.8571
rs 10
c 1
b 0
f 0
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A makeEmpty() 0 3 1
A fromNative() 0 4 1
A isEmpty() 0 3 1
A __toString() 0 3 1
A toNative() 0 3 1
A equals() 0 4 1
1
<?php declare(strict_types=1);
2
/**
3
 * This file is part of the daikon-cqrs/value-object project.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace Daikon\ValueObject;
10
11
use Daikon\Interop\Assertion;
12
use Daikon\Interop\MakeEmptyInterface;
13
14
final class NullValue implements MakeEmptyInterface, ValueObjectInterface
15
{
16
    /** @param null|string $value  */
17 2
    public static function fromNative($value): self
18
    {
19 2
        Assertion::nullOrRegex($value, '#^$#', 'Trying to create NullValue VO from unsupported value.');
20 2
        return new self;
21
    }
22
23 3
    public static function makeEmpty(): self
24
    {
25 3
        return new self;
26
    }
27
28
    public function isEmpty(): bool
29
    {
30
        return true;
31
    }
32
33
    /** @return null */
34 2
    public function toNative()
35
    {
36 2
        return null;
37
    }
38
39
    /** @param self $comparator */
40 1
    public function equals($comparator): bool
41
    {
42 1
        Assertion::isInstanceOf($comparator, self::class);
43 1
        return $this->toNative() === $comparator->toNative();
0 ignored issues
show
Bug introduced by
Are you sure the usage of $comparator->toNative() targeting Daikon\ValueObject\NullValue::toNative() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Bug introduced by
Are you sure the usage of $this->toNative() targeting Daikon\ValueObject\NullValue::toNative() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
44
    }
45
46 1
    public function __toString(): string
47
    {
48 1
        return '';
49
    }
50
}
51