Completed
Push — 1.0 ( 99ef79...ba8fdc )
by David
01:55
created

TwigExtension   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getFunctions() 0 5 1
A getName() 0 3 1
A easyEntity() 0 3 1
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
        $this->entityWrapper = $entityWrapper;
19
    }
20
21
  /**
22
   * {@inheritdoc}
23
   */
24
  public function getFunctions() {
25
      return [
26
          new \Twig_SimpleFunction('easy_entity', [$this, 'easyEntity']),
27
      ];
28
  }
29
30
  /**
31
   * {@inheritdoc}
32
   *
33
   * @deprecated
34
   */
35
  public function getName() {
36
      return 'easy_entity_reader';
37
  }
38
39
    /**
40
     * Wraps an entity object in a "easy" wrapper.
41
     *
42
     * @param EntityInterface $entity
43
     * @return EasyEntityAdapter
44
     */
45
  public function easyEntity(EntityInterface $entity) {
46
      return $this->entityWrapper->wrap($entity);
47
  }
48
}
49