private function validateChannel($channels = [], $returnAsArray = true)
    {
        if ($returnAsArray) {
            if (is_string($channels)) {
                $channels = [$channels];
            }
            if (empty($channels)) {
                return ['public'];
            }
            foreach ($channels as $channel) {
                if (strpos($channel, ' ') !== false) {
                    throw new InvalidChannelException('No spaces are allowed in channel names.');
                }
            }

            return json_encode($channels);
        } else {
            if (empty($channels)) {
                return 'public';
            }
            if (strpos($channels, ' ') !== false) {
                throw new InvalidChannelException('No spaces are allowed in channel names.');
            }

            return $channels;
        }
    }