Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
71.43% covered (warning)
71.43%
5 / 7
66.67% covered (warning)
66.67%
2 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
LexemeTemplateFactory
71.43% covered (warning)
71.43%
5 / 7
66.67% covered (warning)
66.67%
2 / 3
5.58
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 factory
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 render
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2
3namespace Wikibase\Lexeme\Presentation\View\Template;
4
5use Wikibase\View\Template\Template;
6use Wikibase\View\Template\TemplateRegistry;
7
8/**
9 * @license GPL-2.0-or-later
10 * @author Amir Sarabadani <ladsgroup@gmail.com>
11 * @author Thiemo Kreuz
12 */
13class LexemeTemplateFactory {
14
15    /**
16     * @var TemplateRegistry
17     */
18    private $templateRegistry;
19
20    /**
21     * @param string[] $templates
22     */
23    public function __construct( array $templates ) {
24        $this->templateRegistry = new TemplateRegistry( $templates );
25    }
26
27    public static function factory(): self {
28        $templates = include __DIR__ . '/../../../../resources/templates.php';
29        return new self( $templates );
30    }
31
32    /**
33     * Shorthand function to retrieve a template filled with the specified parameters.
34     *
35     * important! note that the Template class does not escape anything.
36     * be sure to escape your params before using this function!
37     *
38     * @param string $key template key
39     * @param array  ...$params normal template parameters
40     *
41     * @return string
42     */
43    public function render( $key, ...$params ) {
44
45        if ( isset( $params[0] ) && is_array( $params[0] ) ) {
46            $params = $params[0];
47        }
48
49        $template = new Template( $this->templateRegistry, $key, $params );
50
51        return $template->render();
52    }
53
54}