Drupal 8 - Country name list by code

By k, 16 July, 2019
/** @var array $countries */
$countries = \Drupal::service('country_manager')
  ->getList();
// Transform TranslatableMarkup object into a string.
array_walk($countries, function (&$translation) {
  /** @var  Drupal\Core\StringTranslation\TranslatableMarkup $translation */
  $translation = $translation->render();
});
var_dump($countries);

Drupal 8 ships with a service to easily retrieve all countries by code. Be sure to use dependency injection.