TwigExtension   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 44
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getFunctions() 0 6 1
A getName() 0 4 1
A easyEntity() 0 4 2
1
<?php
2
3
namespace Drupal\easy_entity_reader;
4
5
use Drupal\Core\Entity\EntityInterface;
6
7
/**
8
 * Twig extension with some useful functions and filters.
9
 */
10
class TwigExtension extends \Twig_Extension
11
{
12
    /**
13
     * @var EntityWrapper
14
     */
15
    private $entityWrapper;
16
17
    public function __construct(EntityWrapper $entityWrapper)
18
    {
19
        $this->entityWrapper = $entityWrapper;
20
    }
21
22
  /**
23
   * {@inheritdoc}
24
   */
25
  public function getFunctions()
26
  {
27
      return [
28
          new \Twig_SimpleFunction('easy_entity', [$this, 'easyEntity']),
29
      ];
30
  }
31
32
  /**
33
   * {@inheritdoc}
34
   *
35
   * @deprecated
36
   */
37
  public function getName()
38
  {
39
      return 'easy_entity_reader';
40
  }
41
42
  /**
43
   * Wraps an entity object in a "easy" wrapper.
44
   *
45
   * @param EntityInterface $entity
46
   *
47
   * @return EasyEntityAdapter
48
   */
49
  public function easyEntity(EntityInterface $entity = null)
50
  {
51
      return $entity ? $this->entityWrapper->wrap($entity) : null;
52
  }
53
}
54