<?php

namespace Drupal\{{ machine_name }};

use Drupal\Core\Entity\EntityTypeManagerInterface;

/**
 * {{ class }} service.
 */
class {{ class }} {

  /**
   * Node storage.
   *
   * @var \Drupal\Node\NodeStorageInterface
   */
  protected $nodeStorage;

  /**
   * Constructs {{ class|article }} object.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager.
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager) {
    $this->nodeStorage = $entity_type_manager->getStorage('node');
  }

  /**
   * Retrieves the last created node.
   */
  public function getLastNode() {
    $nids = $this->nodeStorage->getQuery()
      ->sort('created', 'DESC')
      ->range(0, 1)
      ->execute();
    $nid = reset($nids);
    return $nid ? $this->nodeStorage->load($nid) : FALSE;
  }

}
