Issues (13)

src/NullValue.php (2 issues)

Labels
Severity
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
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...
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