Issues (16)

src/VObjects/Person/NameExtended.php (2 issues)

1
<?php
2
3
declare(strict_types=1);
4
5
namespace DBUnt1tled\VO\VObjects\Person;
6
7
use DBUnt1tled\VO\Exception\InvalidVOArgumentException;
8
use DBUnt1tled\VO\VObjects\Scalar\Strings;
9
use DBUnt1tled\VO\VObjects\ValueObjectInterface;
10
11
class NameExtended extends Name
12
{
13
    /** @var Strings */
14
    private $middleName;
15
16
    /**
17
     * NameExtended constructor.
18
     * @param Strings $firstName
19
     * @param Strings $middleName
20
     * @param Strings $lastName
21
     * @throws \ReflectionException
22
     */
23 2
    public function __construct(Strings $firstName, Strings $middleName, Strings $lastName)
24
    {
25 2
        parent::__construct($firstName, $lastName);
26 2
        $this->guardExtended($middleName);
27 1
        $this->middleName = $middleName;
0 ignored issues
show
Documentation Bug introduced by
$middleName is of type DBUnt1tled\VO\VObjects\ValueObjectInterface, but the property $middleName was declared to be of type DBUnt1tled\VO\VObjects\Scalar\Strings. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
28 1
    }
29
30
    /**
31
     * @param $value
32
     * @param mixed ...$other
33
     */
34 2
    public function guardExtended($value, ...$other): void
0 ignored issues
show
The parameter $other is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

34
    public function guardExtended($value, /** @scrutinizer ignore-unused */ ...$other): void

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
35
    {
36
        /** @var ValueObjectInterface $value*/
37 2
        if (mb_strlen($value->getValue()) < self::NAME_MIN_LENGTH) {
38 1
            throw new InvalidVOArgumentException(sprintf('Middle name must contain a minimum of %s symbols.', self::NAME_MIN_LENGTH), $value);
39
        }
40 1
    }
41
42
    /**
43
     * @param string $firstName
44
     * @param string $middleName
45
     * @param string $lastName
46
     * @return NameExtended
47
     * @throws \ReflectionException
48
     */
49 2
    public static function createFromString(string $firstName, string $middleName, string $lastName = ''): self
50
    {
51 2
        return new static(new Strings($firstName), new Strings($middleName), new Strings($lastName));
52
    }
53
54
    /**
55
     * @return string
56
     */
57 1
    public function getMiddleName(): string
58
    {
59 1
        return $this->middleName->getValue();
60
    }
61
62
    /**
63
     * @return string
64
     */
65 1
    public function getFullName(): string
66
    {
67 1
        return $this->getFirstName().' '.$this->getMiddleName().' '.$this->getLastName();
68
    }
69
}
70