| Conditions | 7 |
| Paths | 10 |
| Total Lines | 30 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 13 | public function __invoke(Request $request) |
||
| 14 | { |
||
| 15 | $channels = Collection::make($this->channelManager->getChannels($request->appId)); |
||
| 16 | |||
| 17 | if ($request->has('filter_by_prefix')) { |
||
| 18 | $channels = $channels->filter(function ($channel, $channelName) use ($request) { |
||
| 19 | return Str::startsWith($channelName, $request->filter_by_prefix); |
||
| 20 | }); |
||
| 21 | } |
||
| 22 | |||
| 23 | $attributes = []; |
||
| 24 | |||
| 25 | if ($request->has('info')) { |
||
| 26 | $attributes = explode(',', trim($request->info)); |
||
| 27 | |||
| 28 | if (in_array('user_count', $attributes) && !Str::startsWith($request->filter_by_prefix, 'presence-')) { |
||
| 29 | throw new HttpException(400, 'Request must be limited to presence channels in order to fetch user_count'); |
||
| 30 | } |
||
| 31 | } |
||
| 32 | |||
| 33 | return [ |
||
| 34 | 'channels' => $channels->map(function ($channel) use ($attributes) { |
||
| 35 | $info = new \stdClass; |
||
| 36 | if (in_array('user_count', $attributes)) { |
||
| 37 | $info->user_count = count($channel->getUsers()); |
||
| 38 | } |
||
| 39 | return $info; |
||
| 40 | })->toArray() ?: new \stdClass, |
||
| 41 | ]; |
||
| 42 | } |
||
| 43 | } |
||
| 44 |