UrlEmbedHelperTrait::urlEmbed()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @file
5
 * Contains Drupal\url_embed\UrlEmbedHelperTrait.
6
 */
7
8
namespace Drupal\url_embed;
9
10
use Drupal\Core\Extension\ModuleHandlerInterface;
11
12
/**
13
 * Wrapper methods for URL embedding.
14
 *
15
 * This utility trait should only be used in application-level code, such as
16
 * classes that would implement ContainerInjectionInterface. Services registered
17
 * in the Container should not use this trait but inject the appropriate service
18
 * directly for easier testing.
19
 */
20
trait UrlEmbedHelperTrait {
21
22
  /**
23
   * The module handler service.
24
   *
25
   * @var \Drupal\Core\Extension\ModuleHandlerInterface.
26
   */
27
  protected $moduleHandler;
28
29
  /**
30
   * The URL embed service.
31
   *
32
   * @var \Drupal\url_embed\UrlEmbedService.
33
   */
34
  protected $url_embed;
35
36
  /**
37
   * Returns the module handler.
38
   *
39
   * @return \Drupal\Core\Extension\ModuleHandlerInterface
40
   *   The module handler.
41
   */
42
  protected function moduleHandler() {
43
    if (!isset($this->moduleHandler)) {
44
      $this->moduleHandler = \Drupal::moduleHandler();
45
    }
46
    return $this->moduleHandler;
47
  }
48
49
  /**
50
   * Sets the module handler service.
51
   *
52
   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
53
   *   The module handler service.
54
   *
55
   * @return self
56
   */
57
  public function setModuleHandler(ModuleHandlerInterface $module_handler) {
58
    $this->moduleHandler = $module_handler;
0 ignored issues
show
Documentation Bug introduced by
It seems like $module_handler of type object<Drupal\Core\Exten...ModuleHandlerInterface> is incompatible with the declared type object<Drupal\Core\Exten...oduleHandlerInterface.> of property $moduleHandler.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
59
    return $this;
60
  }
61
62
  /**
63
   * Returns the URL embed service.
64
   *
65
   * @return \Drupal\url_embed\UrlEmbedInterface
66
   *   The URL embed service..
67
   */
68
  protected function urlEmbed() {
69
    if (!isset($this->url_embed)) {
70
      $this->url_embed = \Drupal::service('url_embed');
71
    }
72
    return $this->url_embed;
73
  }
74
75
  /**
76
   * Sets the URL embed service.
77
   *
78
   * @param \Drupal\url_embed\UrlEmbedInterface $url_embed
79
   *   The URL embed service.
80
   *
81
   * @return self
82
   */
83
  public function setUrlEmbed(UrlEmbedInterface $url_embed) {
84
    $this->url_embed = $url_embed;
0 ignored issues
show
Documentation Bug introduced by
It seems like $url_embed of type object<Drupal\url_embed\UrlEmbedInterface> is incompatible with the declared type object<Drupal\url_embed\UrlEmbedService.> of property $url_embed.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
85
    return $this;
86
  }
87
}
88