Issues (13)

src/BaseValueObject/StringVo.php (1 issue)

1
<?php
2
3
declare(strict_types=1);
4
5
namespace MinimalVo\BaseValueObject;
6
7
use MinimalVo\FactoryTrait\StringVoFactoryTrait;
8
9
/**
10
* @template-extends AbstractVo<string,StringVo>
11
*/
12
final class StringVo extends AbstractVo
13
{
14
    use StringVoFactoryTrait;
15
16
    public function equal($vo): bool
17
    {
18
        return $this->value === $vo->toValue();
19
    }
20
21
    public function duplicate()
22
    {
23
        return new self($this->value);
0 ignored issues
show
Bug Best Practice introduced by
The expression return new self($this->value) returns the type MinimalVo\BaseValueObject\StringVo which is incompatible with the return type mandated by MinimalVo\BaseValueObjec...tInterface::duplicate() of MinimalVo\BaseValueObject\TVo.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
24
    }
25
26
    protected function valid(): bool
27
    {
28
        return true;
29
    }
30
}
31