Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions lib/Segment.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ public static function identify(array $message) {
public static function group(array $message) {
self::checkClient();
$groupId = !empty($message["groupId"]);
self::assert($groupId, "Segment::group() expects groupId");
$userId = !(array_key_exists('userID', $message) && strlen((string) $message['userID']) > 0);

self::assert($groupId && $userId, "Segment::group() expects userId and groupId");
self::validate($message, "group");

return self::$client->group($message);
Expand Down Expand Up @@ -93,8 +95,8 @@ public static function screen(array $message) {
*/
public static function alias(array $message) {
self::checkClient();
$userId = !empty($message["userId"]);
$previousId = !empty($message["previousId"]);
$userId = !(array_key_exists('userID', $message) && strlen((string) $message['userID']) > 0);
$previousId = !(array_key_exists('previousId', $message) && strlen((string) $message['previousId']) > 0);
self::assert($userId && $previousId, "Segment::alias() requires both userId and previousId");

return self::$client->alias($message);
Expand All @@ -107,7 +109,7 @@ public static function alias(array $message) {
* @param string $type
*/
public static function validate($msg, $type){
$userId = !empty($msg["userId"]);
$userId = !(array_key_exists('userID', $msg) && strlen((string) $msg['userID']) > 0);
$anonId = !empty($msg["anonymousId"]);
self::assert($userId || $anonId, "Segment::${type}() requires userId or anonymousId");
}
Expand Down