1 | <?php |
||
20 | class Properties |
||
21 | { |
||
22 | const NAMESPACE_DEFAULT = 'default'; |
||
23 | |||
24 | const NAMESPACE_ENTITY = 'entity'; |
||
25 | |||
26 | /** |
||
27 | * Properties. |
||
28 | * |
||
29 | * @var array |
||
30 | */ |
||
31 | private $properties = []; |
||
32 | |||
33 | /** |
||
34 | * Properties constructor. |
||
35 | * |
||
36 | * @param array $properties Properties. |
||
37 | */ |
||
38 | public function __construct(array $properties = null) |
||
42 | |||
43 | /** |
||
44 | * Get properties. |
||
45 | * |
||
46 | * @param null|string $namespace Property namespace. |
||
47 | * |
||
48 | * @return array |
||
49 | */ |
||
50 | public function getProperties(?string $namespace = null): array |
||
62 | |||
63 | /** |
||
64 | * Check if a property exists. |
||
65 | * |
||
66 | * @param string $propertyName Name of the property. |
||
67 | * @param string $namespace Property namespace. |
||
68 | * |
||
69 | * @return bool |
||
70 | */ |
||
71 | public function hasProperty(string $propertyName, string $namespace = self::NAMESPACE_DEFAULT): bool |
||
79 | |||
80 | /** |
||
81 | * Set a property value. |
||
82 | * |
||
83 | * @param string $propertyName Name of the property. |
||
84 | * @param string $value Value of the property. |
||
85 | * @param string $namespace Property namespace. |
||
86 | * |
||
87 | * @return Properties |
||
88 | */ |
||
89 | public function setProperty(string $propertyName, $value, string $namespace = self::NAMESPACE_DEFAULT): self |
||
95 | |||
96 | /** |
||
97 | * Get the property value. If property does not exist, null is returned. |
||
98 | * |
||
99 | * @param string $propertyName Name of the property. |
||
100 | * @param string $namespace Property namespace. |
||
101 | * |
||
102 | * @return mixed |
||
103 | */ |
||
104 | public function getProperty(string $propertyName, string $namespace = self::NAMESPACE_DEFAULT) |
||
112 | } |
||
113 |
Our type inference engine has found an assignment of a scalar value (like a string, an integer or null) to a property which is an array.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property.
To type hint that a parameter can be either an array or null, you can set a type hint of array and a default value of null. The PHP interpreter will then accept both an array or null for that parameter.
The function can be called with either null or an array for the parameter
$needle
but will only accept an array as$haystack
.