TGetter   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 90 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 0
dl 18
loc 20
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __get() 7 8 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
2
3
namespace Htsl\Helper;
4
5
////////////////////////////////////////////////////////////////
6
7 View Code Duplication
trait TGetter
8
{
9
	/**
10
	 * Allow setting fooBar getter with getFooBar().
11
	 *
12
	 * @access public
13
	 *
14
	 * @param  string $attribute
15
	 *
16
	 * @return mixed
17
	 */
18
	public function __get( $attribute )
19
	{
20
		if( is_callable([static::class, $getter= 'get'.implode('',array_map('ucfirst',explode('_',$attribute))),]) ){
21
			return static::$getter();
22
		}else{
23
			throw new \Exception(static::class.' has no attribute named '.$attribute);
24
		}
25
	}
26
}
0 ignored issues
show
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
27