SimpleRewriteProvider   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 71.43%

Importance

Changes 0
Metric Value
dl 0
loc 31
ccs 5
cts 7
cp 0.7143
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A rewriteTemplateName() 0 2 2
A preprocessTemplateArgs() 0 2 1
1
<?php
2
3
namespace TwigOverride\Providers;
4
5
/**
6
 * A provider that performs simple mapping from one set of templates to another.
7
 *
8
 * Eg.
9
 * "{% include '@test1.twig' %}" => "{% include '@test2.twig' %}"
10
 */
11
class SimpleRewriteProvider implements ProviderInterface {
12
13
  /**
14
   * A map where keys or from template names and values are to template names.
15
   *
16
   * @var string[]
17
   */
18
  protected $templateMap;
19
20
  /**
21
   * Creates a simple template name mapping override provider.
22
   *
23
   * @param string[] $template_map
24
   *   A map where keys or from template names and values are to template names.
25
   */
26 14
  public function __construct(array $template_map) {
27 14
    $this->templateMap = $template_map;
28 14
  }
29
30
  /**
31
   * {@inheritdoc}
32
   */
33 14
  public function rewriteTemplateName($template_name, array $with, array $_context, $only) {
34 14
    return !empty($this->templateMap[$template_name]) ? $this->templateMap[$template_name] : $template_name;
35
  }
36
37
  /**
38
   * {@inheritdoc}
39
   */
40
  public function preprocessTemplateArgs($template_name, array $with, array $_context, $only) {
41
    return $with;
42
  }
43
44
}
45