TemplateResolverDecoratorTrait   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 61
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __clone() 0 4 1
A __call() 0 4 1
A find_renderer() 0 19 4
1
<?php
2
3
/*
4
 * This file is part of the ICanBoogie package.
5
 *
6
 * (c) Olivier Laviale <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace ICanBoogie\Render;
13
14
/**
15
 * An interface for template resolver decorators.
16
 */
17
trait TemplateResolverDecoratorTrait
18
{
19
	/**
20
	 * @var TemplateResolver
21
	 */
22
	protected $template_resolver;
23
24
	/**
25
	 * Initializes the {@link $template_resolver} property.
26
	 *
27
	 * @param TemplateResolver $template_resolver
28
	 */
29
	public function __construct(TemplateResolver $template_resolver)
30
	{
31
		$this->template_resolver = $template_resolver;
32
	}
33
34
	/**
35
	 * Clones {@link $template_resolver}.
36
	 */
37
	public function __clone()
38
	{
39
		$this->template_resolver = clone $this->template_resolver;
40
	}
41
42
	/**
43
	 * Forwards unsupported calls to the decorated template resolver.
44
	 *
45
	 * @param string $method
46
	 * @param array $arguments
47
	 *
48
	 * @return mixed
49
	 */
50
	public function __call($method, $arguments)
51
	{
52
		return call_user_func_array([ $this->template_resolver, $method ], $arguments);
53
	}
54
55
	/**
56
	 * @inheritdoc
57
	 */
58
	public function find_renderer($class)
59
	{
60
		if ($this instanceof $class)
61
		{
62
			return $this;
63
		}
64
65
		if ($this->template_resolver instanceof $class)
66
		{
67
			return $this->template_resolver;
68
		}
69
70
		if ($this->template_resolver instanceof TemplateResolverDecorator)
71
		{
72
			return $this->template_resolver->find_renderer($class);
73
		}
74
75
		return null;
76
	}
77
}
78