Completed
Push — master ( 4a8c3d...7eaefb )
by
unknown
03:53
created

Translatable::__get()   B

Complexity

Conditions 5
Paths 6

Size

Total Lines 22
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 7.4572

Importance

Changes 9
Bugs 2 Features 2
Metric Value
cc 5
eloc 12
c 9
b 2
f 2
nc 6
nop 1
dl 0
loc 22
ccs 7
cts 13
cp 0.5385
crap 7.4572
rs 8.6737
1
<?php
2
3
/**
4
 * This file is part of Zenify
5
 * Copyright (c) 2012 Tomas Votruba (http://tomasvotruba.cz)
6
 */
7
8
namespace Zenify\DoctrineBehaviors\Entities\Attributes;
9
10
11
/**
12
 * @method Translatable proxyCurrentLocaleTranslation($method, $args = [])
13
 */
14
trait Translatable
15
{
16
17
	/**
18
	 * @param string
19
	 * @return mixed
20
	 */
21 2
	public function &__get($name) // "&" intentionally due to compatibility with Nette\Object
22
	{
23 2
		$prefix = 'get';
24 2
		if (preg_match('/^(is|has|should)/i', $name)) {
25
			$prefix = '';
26
		}
27
28 2
		$methodName = $prefix . ucfirst($name);
29
30 2
		if (property_exists($this, $name) === FALSE && method_exists($this, $methodName) === FALSE) {
31 2
			$value = $this->proxyCurrentLocaleTranslation($methodName);
32
			// variable $value intentionally, due to & compatibility
33 2
			return $value;
34
		}
35
36
		if (method_exists($this, $methodName)) {
37
			$value = $this->$methodName();
38
			return $value;
39
		}
40
41
		return $this->$name;
42
	}
43
44
45
	/**
46
	 * @param string
47
	 * @param array
48
	 * @return mixed
49
	 */
50 6
	public function __call($method, $arguments)
51
	{
52 6
		return $this->proxyCurrentLocaleTranslation($method, $arguments);
53
	}
54
55
}
56