allejo /
bzion
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * This file contains a conversation event |
||
| 4 | * |
||
| 5 | * @license https://github.com/allejo/bzion/blob/master/LICENSE.md GNU General Public License Version 3 |
||
| 6 | */ |
||
| 7 | |||
| 8 | namespace BZIon\Event; |
||
| 9 | |||
| 10 | /** |
||
| 11 | * Event thrown when players join a conversation |
||
| 12 | */ |
||
| 13 | class ConversationJoinEvent extends Event |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * @var \Conversation |
||
| 17 | */ |
||
| 18 | protected $conversation; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @var \Model[] |
||
| 22 | */ |
||
| 23 | protected $members; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Create a new event |
||
| 27 | * |
||
| 28 | * @param \Conversation $conversation The conversation in question |
||
| 29 | * @param \Model[] $members The players and teams who joined the conversation |
||
| 30 | */ |
||
| 31 | public function __construct(\Conversation $conversation, array $members) |
||
| 32 | { |
||
| 33 | $this->conversation = $conversation; |
||
| 34 | $this->members = $members; |
||
| 35 | } |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Get the conversation that was renamed |
||
| 39 | * |
||
| 40 | * @return \Conversation |
||
| 41 | */ |
||
| 42 | public function getConversation() |
||
| 43 | { |
||
| 44 | return $this->conversation; |
||
| 45 | } |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Get the Players and Teams who joined the conversation |
||
| 49 | * |
||
| 50 | * @return \Model[] |
||
| 51 | */ |
||
| 52 | public function getNewMembers() |
||
| 53 | { |
||
| 54 | return $this->members; |
||
| 55 | } |
||
| 56 | |||
| 57 | /** |
||
| 58 | * {@inheritdoc} |
||
| 59 | */ |
||
| 60 | public function serialize() |
||
| 61 | { |
||
| 62 | $players = $teams = array(); |
||
| 63 | |||
| 64 | foreach ($this->members as $member) { |
||
| 65 | if ($member instanceof \Player) { |
||
| 66 | $players[] = $member; |
||
| 67 | } else { |
||
| 68 | $teams[] = $member; |
||
| 69 | } |
||
| 70 | } |
||
| 71 | |||
| 72 | return serialize(array( |
||
| 73 | 'conversation' => $this->conversation->getId(), |
||
| 74 | 'players' => \Player::mapToIDs($players), |
||
| 75 | 'teams' => \Team::mapToIDs($teams) |
||
| 76 | )); |
||
| 77 | } |
||
| 78 | |||
| 79 | /** |
||
| 80 | * {@inheritdoc} |
||
| 81 | */ |
||
| 82 | public function unserialize($data) |
||
| 83 | { |
||
| 84 | $data = unserialize($data); |
||
| 85 | |||
| 86 | $conversation = \Conversation::get($data['conversation']); |
||
| 87 | |||
| 88 | $players = \Player::arrayIdToModel($data['players']); |
||
| 89 | $teams = \Team::arrayIdToModel($data['teams']); |
||
| 90 | |||
| 91 | $this->__construct($conversation, array_merge($players, $teams)); |
||
|
0 ignored issues
–
show
|
|||
| 92 | } |
||
| 93 | } |
||
| 94 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: