BasePackage::getInstance()   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 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Drupal\qa;
6
7
/**
8
 * An instantiable Exportable.
9
 */
10
abstract class BasePackage extends Exportable {
11
12
  /**
13
   * The plugin instances.
14
   *
15
   * @var array
16
   */
17
  protected static $instances = [];
18
19
  /**
20
   * Get a new or existing plugin instance.
21
   *
22
   * @return mixed
23
   *   The plugin.
24
   */
25
  public static function getInstance() {
26
    $name = get_called_class();
27
    if (!isset(self::$instances[$name])) {
28
      self::$instances[$name] = new $name();;
29
    }
30
    return self::$instances[$name];
31
  }
32
33
}
34