-
Notifications
You must be signed in to change notification settings - Fork 0
/
ChannelCollection.php
59 lines (50 loc) · 1.38 KB
/
ChannelCollection.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
declare(strict_types=1);
namespace voniersa\twitch\livechat;
use ArrayIterator;
class ChannelCollection
{
private array $collection;
/**
* @throws IncorrectDataProvidedException
*/
private function __construct(array $channels)
{
foreach ($channels as $channel) {
if (!($channel instanceof ChannelName)) {
throw new IncorrectDataProvidedException("Instance of ChannelName was expected.");
}
$this->add($channel);
}
}
/**
* @param array $channels list of channels where the chatbot is active
* @return ChannelCollection collection of channels where the chatbot is active
* @throws IncorrectDataProvidedException
*/
public static function fromArray(array $channels): ChannelCollection
{
return new self($channels);
}
/**
* @return ArrayIterator iterator for all channels
*/
public function getIterator(): ArrayIterator
{
return new ArrayIterator($this->collection);
}
/**
* @return int number of channels in collection
*/
public function count(): int
{
return count($this->collection);
}
/**
* @param ChannelName $channel channel that needs to be added to the collection
*/
public function add(ChannelName $channel): void
{
$this->collection[] = $channel;
}
}