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

NullValue::equals()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
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