SimpleRewriteProvider::rewriteTemplateName()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 1
nc 2
nop 4
dl 0
loc 2
ccs 2
cts 2
cp 1
crap 2
rs 10
c 0
b 0
f 0
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