| Total Complexity | 4 |
| Total Lines | 44 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 12 | final class Assert extends TestCase |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | * Gets an inaccessible object property. |
||
| 16 | * |
||
| 17 | * @param bool $revoke whether to make property inaccessible after getting. |
||
| 18 | */ |
||
| 19 | public static function getInaccessibleProperty(object $object, string $propertyName, bool $revoke = true): mixed |
||
| 20 | { |
||
| 21 | $class = new ReflectionClass($object); |
||
| 22 | |||
| 23 | while (!$class->hasProperty($propertyName)) { |
||
| 24 | $class = $class->getParentClass(); |
||
| 25 | } |
||
| 26 | |||
| 27 | $property = $class->getProperty($propertyName); |
||
| 28 | |||
| 29 | $property->setAccessible(true); |
||
| 30 | |||
| 31 | $result = $property->getValue($object); |
||
| 32 | |||
| 33 | if ($revoke) { |
||
| 34 | $property->setAccessible(false); |
||
| 35 | } |
||
| 36 | |||
| 37 | return $result; |
||
| 38 | } |
||
| 39 | |||
| 40 | /** |
||
| 41 | * Invokes an inaccessible method. |
||
| 42 | * |
||
| 43 | * @param object $object The object to invoke the method on. |
||
| 44 | * @param string $method The name of the method to invoke. |
||
| 45 | * @param array $args The arguments to pass to the method. |
||
| 46 | * |
||
| 47 | * @throws ReflectionException |
||
| 48 | */ |
||
| 49 | public static function invokeMethod(object $object, string $method, array $args = []): mixed |
||
| 56 | } |
||
| 57 | } |
||
| 58 |