Verified Commit a55b4e7d authored by Dave Long's avatar Dave Long
Browse files

task: #3490713 Return the correct typehint when Drupal::service() is called with a class string

By: donquixote
By: bradjones1
By: james.williams
By: longwave
By: mstrelan
By: kim.pepper
By: godotislate
By: berdir
(cherry picked from commit 76a93eec)
parent 1462e3d2
Loading
Loading
Loading
Loading
Loading
+5 −7
Original line number Diff line number Diff line
@@ -193,17 +193,15 @@ public static function hasContainer() {
  /**
   * Retrieves a service from the container.
   *
   * Use this method if the desired service is not one of those with a dedicated
   * accessor method below. If it is listed below, those methods are preferred
   * as they can return useful type hints.
   *
   * @param string $id
   * @param class-string<T>|string $id
   *   The ID of the service to retrieve.
   *
   * @return mixed
   * @template T of object
   *
   * @return ($id is class-string<T> ? T : object)
   *   The specified service.
   */
  public static function service($id) {
  public static function service(string $id): object {
    return static::getContainer()->get($id);
  }