IntegerVo::valid()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MinimalVo\BaseValueObject;
6
7
use MinimalVo\FactoryTrait\IntegerVoFactoryTrait;
8
9
/**
10
* @template-extends AbstractVo<int,IntegerVo>
11
*/
12
final class IntegerVo extends AbstractVo
13
{
14
    use IntegerVoFactoryTrait;
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\IntegerVo 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 is_int($this->value);
29
    }
30
}
31