Passed
Push — master ( a657bc...a42b30 )
by
unknown
61:11 queued 10s
created

WebTemplatingFactory   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
dl 0
loc 24
rs 10
c 1
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A newTemplatingEnvionment() 0 22 1
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace WMDE\Fundraising\Frontend\Factories;
6
7
use Twig\Environment;
8
use Twig\TwigFunction;
9
use WMDE\Fundraising\ContentProvider\ContentProvider;
10
use WMDE\Fundraising\Frontend\Presentation\FilePrefixer;
11
12
class WebTemplatingFactory extends TwigFactory {
13
14
	public function newTemplatingEnvionment( array $translations, ContentProvider $contentProvider, FilePrefixer $filePrefixer, array $globals ): Environment {
15
		$filters = [
16
			$this->newFilePrefixFilter( $filePrefixer )
17
		];
18
		$functions = [
19
			new TwigFunction(
20
				'web_content',
21
				function ( string $name, array $context = [] ) use( $contentProvider ): string {
22
					return $contentProvider->getWeb( $name, $context );
23
				},
24
				[ 'is_safe' => [ 'html' ] ]
25
			),
26
			new TwigFunction(
27
				'translations',
28
				function () use ( $translations ): string {
29
					return json_encode( $translations );
30
				},
31
				[ 'is_safe' => [ 'html' ] ]
32
			),
33
		];
34
35
		return $this->newTwigEnvironment( $filters, $functions, $globals );
36
	}
37
}
38