Completed
Push — master ( 170171...e699ef )
by Peter
25:38
created

PhpTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 62
Duplicated Lines 32.26 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 5
c 2
b 1
f 0
lcom 1
cbo 3
dl 20
loc 62
rs 10

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Renderers;
4
5
use Maslosoft\MiniView\MiniView;
6
use Maslosoft\MiniView\Renderers\PhpRenderer;
7
use UnitTester;
8
9
class PhpTest extends \Codeception\TestCase\Test
10
{
11
12
	/**
13
	 * @var UnitTester
14
	 */
15
	protected $tester;
16
17
	/**
18
	 * NOTE: Do not remove, part of test
19
	 * @var string
20
	 */
21
	public $value = 'property value';
22
23
	// tests
24
	public function testIfWillPassVariableToView()
25
	{
26
		$var = 'New Variable';
27
28
		$view = new MiniView($this);
29
30
		$result = $view->render('passVariable', ['var' => $var], true);
31
32
		$this->assertSame($var, $result);
33
	}
34
35
	// tests
36
	public function testIfWillPassVariableToViewWithRendererDetection()
37
	{
38
		$var = 'New Variable';
39
40
		$view = new MiniView($this);
41
		$view->setRenderer(new PhpRenderer());
42
		$result = $view->render('passVariable.php', ['var' => $var], true);
43
44
		$this->assertSame($var, $result);
45
	}
46
47
	public function testIfWillForwardMethodToOwner()
48
	{
49
		$view = new MiniView($this);
50
51
		$result = $view->render('forwardMethod', [], true);
52
53
		$this->assertSame($this->getValue(), $result);
54
	}
55
56
	public function testIfWillForwardPropertyToOwner()
57
	{
58
		$view = new MiniView($this);
59
60
		$result = $view->render('forwardProperty', [], true);
61
62
		$this->assertSame($this->value, $result);
63
	}
64
65
	public function getValue()
66
	{
67
		return 'my value from method';
68
	}
69
70
}
71