1 | <?php |
||
11 | trait ObjectAssertTrait |
||
12 | { |
||
13 | /** |
||
14 | * Perform an instanceof assertion. |
||
15 | * |
||
16 | * @param object $object |
||
17 | * @param string $class |
||
18 | * @param string $message |
||
19 | */ |
||
20 | public function isInstanceOf($object, $class, $message = '') |
||
26 | |||
27 | /** |
||
28 | * Perform a negated instanceof assertion. |
||
29 | * |
||
30 | * @param object $object |
||
31 | * @param string $class |
||
32 | * @param string $message |
||
33 | */ |
||
34 | public function notInstanceOf($object, $class, $message = '') |
||
40 | |||
41 | /** |
||
42 | * Perform a property assertion. |
||
43 | * |
||
44 | * @param array|object $object |
||
45 | * @param string $property |
||
46 | * @param string $message |
||
47 | */ |
||
48 | public function property($object, $property, $message = '') |
||
54 | |||
55 | /** |
||
56 | * Perform a negated property assertion. |
||
57 | * |
||
58 | * @param array|object $object |
||
59 | * @param string $property |
||
60 | * @param string $message |
||
61 | */ |
||
62 | public function notProperty($object, $property, $message = '') |
||
68 | |||
69 | /** |
||
70 | * Perform a deep property assertion. |
||
71 | * |
||
72 | * @param array|object $object |
||
73 | * @param string $property |
||
74 | * @param string $message |
||
75 | */ |
||
76 | public function deepProperty($object, $property, $message = '') |
||
82 | |||
83 | /** |
||
84 | * Perform a negated deep property assertion. |
||
85 | * |
||
86 | * @param array|object $object |
||
87 | * @param string $property |
||
88 | * @param string $message |
||
89 | */ |
||
90 | public function notDeepProperty($object, $property, $message = '') |
||
96 | |||
97 | /** |
||
98 | * Perform a property value assertion. |
||
99 | * |
||
100 | * @param array|object $object |
||
101 | * @param string $property |
||
102 | * @param mixed $value |
||
103 | * @param string $message |
||
104 | */ |
||
105 | public function propertyVal($object, $property, $value, $message = '') |
||
111 | |||
112 | /** |
||
113 | * Perform a negated property value assertion. |
||
114 | * |
||
115 | * @param array|object $object |
||
116 | * @param string $property |
||
117 | * @param mixed $value |
||
118 | * @param string $message |
||
119 | */ |
||
120 | public function propertyNotVal($object, $property, $value, $message = '') |
||
126 | |||
127 | /** |
||
128 | * Perform a deep property value assertion. |
||
129 | * |
||
130 | * @param array|object $object |
||
131 | * @param string $property |
||
132 | * @param mixed $value |
||
133 | * @param string $message |
||
134 | */ |
||
135 | public function deepPropertyVal($object, $property, $value, $message = '') |
||
141 | |||
142 | /** |
||
143 | * Perform a negated deep property value assertion. |
||
144 | * |
||
145 | * @param array|object $object |
||
146 | * @param string $property |
||
147 | * @param mixed $value |
||
148 | * @param string $message |
||
149 | */ |
||
150 | public function deepPropertyNotVal($object, $property, $value, $message = '') |
||
156 | } |
||
157 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: