Use Key::STATE_NAMED and Key::STATE_INCOMPLETE to check value.
Example:
An incomplete key does not have an ID on its last path element.
$key = $datastore->key('parent', 1234)
->pathElement('child');
if ($key->state() === Key::STATE_INCOMPLETE) {
echo 'Key is incomplete!';
}
A named key has a kind and an identifier on each path element.
$key = $datastore->key('parent', 1234)
->pathElement('child', 4321);
if ($key->state() === Key::STATE_NAMED) {
echo 'Key is named!';
}