TestRewriteProvider::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace TwigOverride\Test\Providers;
4
5
use TwigOverride\Providers\SimpleRewriteProvider;
6
7
/**
8
 * A provider for functional testing.
9
 */
10
class TestRewriteProvider extends SimpleRewriteProvider {
11
12
  /**
13
   * A map of rewrites.
14
   *
15
   * @var array
16
   */
17
  private $paramMap;
18
19
  /**
20
   * Creates a TestRewriteProvider object.
21
   *
22
   * @param array $template_map
23
   *   A map where keys are 'from' template names and values are 'to' template
24
   *   names.
25
   * @param array $param_map
26
   *   A map where keys are 'from' param names and values are 'to' param names.
27
   */
28
  public function __construct(array $template_map, array $param_map) {
29
    parent::__construct($template_map);
30
    $this->paramMap = $param_map;
31
  }
32
33
  /**
34
   * {@inheritdoc}
35
   */
36
  public function preprocessTemplateArgs($template_name, array $with, array $_context, $only) {
37
    foreach ($with as $key => $value) {
38
      if (!empty($this->paramMap[$key])) {
39
        $with[$key] = $this->paramMap[$key];
40
      }
41
    }
42
    return $with;
43
  }
44
45
}
46