RendererAwareTrait   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 37
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getRenderer() 0 8 2
A setRenderer() 0 9 2
1
<?php
2
3
/**
4
 * This software package is licensed under `AGPL, Commercial` license[s].
5
 *
6
 * @package maslosoft/miniview
7
 * @license AGPL, Commercial
8
 *
9
 * @copyright Copyright (c) Peter Maselkowski <[email protected]>
10
 *
11
 * @link http://maslosoft.com/miniview/
12
 */
13
14
namespace Maslosoft\MiniView\Traits;
15
16
use Maslosoft\MiniView\Interfaces\OwnerAwareInterface;
17
use Maslosoft\MiniView\Interfaces\ViewRendererInterface;
18
use Maslosoft\MiniView\Renderers\PhpRenderer;
19
20
/**
21
 * RendererAwareTrait
22
 *
23
 * @author Piotr Maselkowski <pmaselkowski at gmail.com>
24
 */
25
trait RendererAwareTrait
26
{
27
28
	/**
29
	 *
30
	 * @var ViewRendererInterface
31
	 */
32
	private $renderer = null;
33
34
	/**
35
	 * Get renderer
36
	 * @return ViewRendererInterface
37
	 */
38
	public function getRenderer()
39
	{
40
		if (null === $this->renderer)
41
		{
42
			$this->setRenderer(new PhpRenderer());
43
		}
44
		return $this->renderer;
45
	}
46
47
	/**
48
	 * Set renderer
49
	 * @param ViewRendererInterface $renderer
50
	 * @return static
51
	 */
52
	public function setRenderer(ViewRendererInterface $renderer)
53
	{
54
		if ($renderer instanceof OwnerAwareInterface)
55
		{
56
			$renderer->setOwner($this->getOwner());
1 ignored issue
show
Bug introduced by
It seems like getOwner() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
57
		}
58
		$this->renderer = $renderer;
59
		return $this;
60
	}
61
}
62