It is done at Utilities::getEntityId. Second argument ('WindowsAzure\MediaServices\Models\Asset') restricts $asset to be either a string or WindowsAzure\MediaServices\Models\Asset. In other case the exception would be thrown.