Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
92.86% |
13 / 14 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| DumpUtils | |
92.86% |
13 / 14 |
|
0.00% |
0 / 1 |
8.02 | |
0.00% |
0 / 1 |
| objectToArray | |
92.86% |
13 / 14 |
|
0.00% |
0 / 1 |
8.02 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Wikimedia\DebugInfo; |
| 4 | |
| 5 | /** |
| 6 | * @since 1.40 |
| 7 | */ |
| 8 | class DumpUtils { |
| 9 | /** |
| 10 | * Convert an object to an array by casting, but filter the properties |
| 11 | * to make recursive dumping more feasible. |
| 12 | * |
| 13 | * @phpcs:ignore MediaWiki.Commenting.FunctionComment.ObjectTypeHintParam |
| 14 | * @param object $object |
| 15 | * @return array |
| 16 | * @throws \ReflectionException |
| 17 | */ |
| 18 | public static function objectToArray( $object ) { |
| 19 | $vars = (array)$object; |
| 20 | $class = new \ReflectionClass( $object ); |
| 21 | while ( $class ) { |
| 22 | foreach ( $class->getProperties() as $property ) { |
| 23 | if ( AnnotationReader::propertyHasAnnotation( $property, 'noVarDump' ) ) { |
| 24 | // Ref: zend_declare_typed_property(), zend_mangle_property_name() |
| 25 | if ( $property->isPrivate() ) { |
| 26 | $mangledName = "\0{$class->name}\0{$property->name}"; |
| 27 | } elseif ( $property->isProtected() ) { |
| 28 | $mangledName = "\0*\0{$property->name}"; |
| 29 | } else { |
| 30 | $mangledName = $property->name; |
| 31 | } |
| 32 | if ( isset( $vars[$mangledName] ) && !is_scalar( $vars[$mangledName] ) ) { |
| 33 | $vars[$mangledName] = new Placeholder( $vars[$mangledName] ); |
| 34 | } |
| 35 | } |
| 36 | } |
| 37 | $class = $class->getParentClass(); |
| 38 | } |
| 39 | return $vars; |
| 40 | } |
| 41 | } |