1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: gareth |
5
|
|
|
* Date: 27-8-15 |
6
|
|
|
* Time: 10:27 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace garethp\ews\API; |
10
|
|
|
|
11
|
|
|
use garethp\ews\Caster; |
|
|
|
|
12
|
|
|
|
13
|
|
|
trait MagicMethodsTrait |
14
|
|
|
{ |
15
|
37 |
|
public function __set($name, $value) |
16
|
|
|
{ |
17
|
37 |
|
if (is_object($value) && !($value instanceof Type) && property_exists($value, "Entry")) { |
18
|
7 |
|
$value = $value->Entry; |
19
|
|
|
} |
20
|
|
|
|
21
|
37 |
|
if ($this->methodExists("set" . ucfirst($name))) { |
22
|
37 |
|
$convertedValue = $this->convertValueToExpectedType($value, $name); |
23
|
37 |
|
$this->{"set" . ucfirst($name)}($convertedValue); |
24
|
37 |
|
return; |
25
|
|
|
} |
26
|
|
|
|
27
|
5 |
|
if (!$this->exists($name) && $this->exists(lcfirst($name))) { |
28
|
|
|
$name = lcfirst($name); |
29
|
|
|
} |
30
|
|
|
|
31
|
5 |
|
$this->$name = $value; |
32
|
|
|
} |
33
|
|
|
|
34
|
36 |
|
public function exists($name) |
35
|
|
|
{ |
36
|
36 |
|
return property_exists($this, $name); |
37
|
|
|
} |
38
|
|
|
|
39
|
37 |
|
public function methodExists($name) |
40
|
|
|
{ |
41
|
37 |
|
return method_exists($this, $name); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Automatically convert stdClass objects to proper EWS types |
46
|
|
|
* |
47
|
|
|
* @param mixed $value The value to convert |
48
|
|
|
* @param string $propertyName The property name |
49
|
|
|
* @return mixed Converted value |
50
|
|
|
*/ |
51
|
37 |
|
private function convertValueToExpectedType($value, string $propertyName) |
52
|
|
|
{ |
53
|
37 |
|
if (!TypeConverter::containsStdClass($value)) { |
54
|
37 |
|
return $value; |
55
|
|
|
} |
56
|
|
|
|
57
|
2 |
|
$expectedType = $this->getExpectedTypeFromSetter($propertyName); |
58
|
|
|
|
59
|
2 |
|
if ($expectedType) { |
60
|
2 |
|
return TypeConverter::convertToType($value, $expectedType); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
return $value; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Get expected type from setter method using reflection |
68
|
|
|
* |
69
|
|
|
* @param string $propertyName Property name |
70
|
|
|
* @return string|null Expected type class name |
71
|
|
|
*/ |
72
|
2 |
|
private function getExpectedTypeFromSetter(string $propertyName): ?string |
73
|
|
|
{ |
74
|
2 |
|
$methodName = "set" . ucfirst($propertyName); |
75
|
|
|
|
76
|
2 |
|
if (!method_exists($this, $methodName)) { |
77
|
|
|
return null; |
78
|
|
|
} |
79
|
|
|
|
80
|
2 |
|
$reflection = new \ReflectionMethod($this, $methodName); |
81
|
2 |
|
$parameters = $reflection->getParameters(); |
82
|
|
|
|
83
|
2 |
|
if (empty($parameters)) { |
84
|
|
|
return null; |
85
|
|
|
} |
86
|
|
|
|
87
|
2 |
|
$type = $parameters[0]->getType(); |
88
|
|
|
|
89
|
|
|
// Handle union types (e.g., array|InternetHeaderType) |
90
|
2 |
|
if ($type instanceof \ReflectionUnionType) { |
91
|
2 |
|
foreach ($type->getTypes() as $unionType) { |
92
|
2 |
|
if (!$unionType->isBuiltin() && $unionType->getName() !== 'array') { |
93
|
2 |
|
return $unionType->getName(); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
// Handle single types |
99
|
|
|
if ($type && !$type->isBuiltin()) { |
100
|
|
|
return $type->getName(); |
|
|
|
|
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
return null; |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths