1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace GloBee\PaymentApi\Models; |
4
|
|
|
|
5
|
|
|
trait PropertyTrait |
6
|
|
|
{ |
7
|
|
|
/** |
8
|
|
|
* @param $key |
9
|
|
|
* @param $value |
10
|
|
|
*/ |
11
|
4 |
|
protected function setProperty($name, $value) |
12
|
|
|
{ |
13
|
4 |
|
$methodName = 'set'.$this->strToStudlyCase($name); |
14
|
4 |
|
if (method_exists($this, $methodName)) { |
15
|
2 |
|
$this->{$methodName}($value); |
16
|
|
|
|
17
|
2 |
|
return; |
18
|
|
|
} |
19
|
|
|
|
20
|
4 |
|
if (property_exists($this, $name)) { |
21
|
4 |
|
$this->{$name} = $value; |
22
|
|
|
|
23
|
4 |
|
return; |
24
|
|
|
} |
25
|
|
|
} |
26
|
|
|
|
27
|
6 |
|
public function __call($name, $arguments) |
28
|
|
|
{ |
29
|
6 |
|
$mutator = substr($name, 0, 3); |
30
|
6 |
|
if ($mutator === 'get') { |
31
|
6 |
|
return $this->__get(lcfirst(substr($name, 3))); |
32
|
|
|
} |
33
|
|
|
|
34
|
1 |
|
if ($mutator === 'set') { |
35
|
1 |
|
return $this->__set(lcfirst(substr($name, 3)), $arguments[0]); |
|
|
|
|
36
|
|
|
} |
37
|
|
|
} |
38
|
|
|
|
39
|
10 |
|
public function __get($name) |
40
|
|
|
{ |
41
|
10 |
|
$methodName = 'get'.$this->strToStudlyCase($name); |
42
|
10 |
|
if (method_exists($this, $methodName)) { |
43
|
|
|
return $this->{$methodName}(); |
44
|
|
|
} |
45
|
|
|
|
46
|
10 |
|
if (property_exists($this, $name)) { |
47
|
10 |
|
return $this->{$name}; |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|
51
|
4 |
|
public function __set($name, $value) |
52
|
|
|
{ |
53
|
4 |
|
$this->setProperty($name, $value); |
54
|
4 |
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param $key |
58
|
|
|
* |
59
|
|
|
* @return mixed |
60
|
|
|
*/ |
61
|
10 |
|
protected function strToStudlyCase($key) |
62
|
|
|
{ |
63
|
10 |
|
return str_replace(' ', '', ucwords(str_replace('_', ' ', $key))); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.