Translatable::__get()   B
last analyzed

Complexity

Conditions 5
Paths 6

Size

Total Lines 22
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 5

Importance

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