HasLayouts   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 54
Duplicated Lines 33.33 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 18
loc 54
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A debug() 9 9 2
getLayoutData() 0 1 ?
getLayoutPaths() 0 1 ?
A render() 9 9 2

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
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 18 and the first side effect is on line 11.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * Joomla! common library.
4
 *
5
 * @copyright  Copyright (C) 2017 Roberto Segura López, Inc. All rights reserved.
6
 * @license    GNU/GPL 2, http://www.gnu.org/licenses/gpl-2.0.htm
7
 */
8
9
namespace Phproberto\Joomla\Traits;
10
11 1
defined('JPATH_PLATFORM') || die;
12
13
/**
14
 * Modules that use JLayoutFile as renderer.
15
 *
16
 * @since  0.0.1
17
 */
18
trait HasLayouts
19
{
20
	/**
21
	 * Debug a layout rendering.
22
	 *
23
	 * @param   string  $layoutId  Layout identifier
24
	 * @param   array   $data      Optional data for the layout
25
	 *
26
	 * @return  string
27
	 */
28 1 View Code Duplication
	public function debug($layoutId = null, $data = array())
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
29
	{
30 1
		$layoutId = $layoutId ?: 'default';
31
32 1
		$renderer = new \JLayoutFile($layoutId);
33 1
		$renderer->setIncludePaths($this->getLayoutPaths());
34
35 1
		return $renderer->debug(array_merge($this->getLayoutData(), $data));
36
	}
37
38
	/**
39
	 * Get the data that will be sent to the layout.
40
	 *
41
	 * @param   boolean   $reload  Force reloading data
42
	 *
43
	 * @return  array
44
	 */
45
	abstract protected function getLayoutData($reload = false);
46
47
	/**
48
	 * Get the paths where we will search for layouts.
49
	 *
50
	 * @return  string[]
51
	 */
52
	abstract protected function getLayoutPaths();
53
54
	/**
55
	 * Render a layout.
56
	 *
57
	 * @param   string  $layoutId  Layout identifier
58
	 * @param   array   $data      Optional data for the layout
59
	 *
60
	 * @return  string
61
	 */
62 1 View Code Duplication
	public function render($layoutId = null, $data = array())
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
63
	{
64 1
		$layoutId = $layoutId ?: 'default';
65
66 1
		$renderer = new \JLayoutFile($layoutId);
67 1
		$renderer->setIncludePaths($this->getLayoutPaths());
68
69 1
		return $renderer->render(array_merge($this->getLayoutData(), $data));
70
	}
71
}
72