Issues (15)

examples/bst/AddressBookEntry.php (1 issue)

Labels
Severity
1
<?php
2
/*
3
 * Forest: PhoneBookEntry.php
4
 * User: Sebastian Böttger <[email protected]>
5
 * created at 24.12.19, 14:57
6
 */
7
8
use Seboettg\Collection\Comparable\Comparable;
9
use Seboettg\Forest\Item\ItemInterface;
10
11
class AddressBookEntry implements ItemInterface
12
{
13
14
    /**
15
     * @var string
16
     */
17
    protected $firstName;
18
19
    /**
20
     * @var string
21
     */
22
    protected $lastName;
23
24
    /**
25
     * @var string
26
     */
27
    protected $address;
28
29
    /**
30
     * @var string
31
     */
32
    protected $phoneNumber;
33
34
    public function __construct(string $lastName, string $firstName, ?string $address = null, ?string $phoneNumber = null)
35
    {
36
        $this->lastName = $lastName;
37
        $this->firstName = $firstName;
38
        $this->address = $address;
39
        $this->phoneNumber = $phoneNumber;
40
    }
41
42
    public function getCompareValue()
43
    {
44
        return $this->lastName . "," . $this->firstName;
45
    }
46
47
    /**
48
     * @param Comparable|AddressBookEntry $b
49
     * @return int
50
     */
51
    public function compareTo(Comparable $b): int
52
    {
53
        return strcasecmp($this->getCompareValue(), $b->getCompareValue());
0 ignored issues
show
The method getCompareValue() does not exist on Seboettg\Collection\Comparable\Comparable. It seems like you code against a sub-type of Seboettg\Collection\Comparable\Comparable such as AddressBookEntry. ( Ignorable by Annotation )

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

53
        return strcasecmp($this->getCompareValue(), $b->/** @scrutinizer ignore-call */ getCompareValue());
Loading history...
54
    }
55
56
    /**
57
     * @param ItemInterface|AddressBookEntry $item
58
     * @return bool
59
     */
60
    public function equals(ItemInterface $item): bool
61
    {
62
        return $this->compareTo($item) === 0;
63
    }
64
65
    /**
66
     * @return string
67
     */
68
    public function getFirstName(): string
69
    {
70
        return $this->firstName;
71
    }
72
73
    /**
74
     * @return string
75
     */
76
    public function getLastName(): string
77
    {
78
        return $this->lastName;
79
    }
80
81
    /**
82
     * @return string
83
     */
84
    public function getPhoneNumber(): string
85
    {
86
        return $this->phoneNumber;
87
    }
88
89
    /**
90
     * @return string
91
     */
92
    public function getAddress(): string
93
    {
94
        return $this->address;
95
    }
96
97
}
98