1 | <?php |
||
2 | /** |
||
3 | * Routing table |
||
4 | * User: moyo |
||
5 | * Date: 2018/11/22 |
||
6 | * Time: 4:52 PM |
||
7 | */ |
||
8 | |||
9 | namespace Carno\Net\Routing; |
||
10 | |||
11 | use Carno\Net\Endpoint; |
||
12 | |||
13 | class Table |
||
14 | { |
||
15 | /** |
||
16 | * @var Endpoint[] |
||
17 | */ |
||
18 | private $current = []; |
||
19 | |||
20 | /** |
||
21 | * @param Endpoint ...$presents |
||
22 | * @return Changed[] |
||
23 | */ |
||
24 | public function reset(Endpoint ...$presents) : array |
||
25 | { |
||
26 | $changes = []; |
||
27 | |||
28 | $current = []; |
||
29 | |||
30 | foreach ($presents as $endpoint) { |
||
31 | $current[$epn = $endpoint->id()] = $endpoint; |
||
32 | |||
33 | // if exists |
||
34 | if (isset($this->current[$epn])) { |
||
35 | unset($this->current[$epn]); |
||
36 | continue; |
||
37 | } |
||
38 | |||
39 | // mark join |
||
40 | $changes[] = new Changed(Events::JOIN, $endpoint); |
||
41 | } |
||
42 | |||
43 | if ($this->current) { |
||
0 ignored issues
–
show
|
|||
44 | foreach ($this->current as $endpoint) { |
||
45 | // mark leave |
||
46 | $changes[] = new Changed(Events::LEAVE, $endpoint); |
||
47 | } |
||
48 | } |
||
49 | |||
50 | $this->current = $current; |
||
51 | |||
52 | return $changes; |
||
53 | } |
||
54 | } |
||
55 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.