Passed
Push — master ( ebf7ef...bfd014 )
by Mr
05:29
created

NullValue   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 30
ccs 12
cts 12
cp 1
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A makeEmpty() 0 3 1
A __toString() 0 3 1
A toNative() 0 3 1
A fromNative() 0 4 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 Assert\Assertion;
12
13
final class NullValue implements ValueObjectInterface
14
{
15
    /** @param null|string $value  */
16 2
    public static function fromNative($value): self
17
    {
18 2
        Assertion::nullOrRegex($value, '#^$#', 'Trying to create NullValue VO from unsupported value.');
19 2
        return new self;
20
    }
21
22 3
    public static function makeEmpty(): self
23
    {
24 3
        return new self;
25
    }
26
27
    /** @return null */
28 2
    public function toNative()
29
    {
30 2
        return null;
31
    }
32
33
    /** @param self $comparator */
34 1
    public function equals($comparator): bool
35
    {
36 1
        Assertion::isInstanceOf($comparator, self::class);
37 1
        return $this->toNative() === $comparator->toNative();
0 ignored issues
show
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...
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...
38
    }
39
40 1
    public function __toString(): string
41
    {
42 1
        return '';
43
    }
44
}
45