| Conditions | 7 |
| Total Lines | 40 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 20 |
| CRAP Score | 7 |
| Changes | 0 | ||
| 1 | <?php |
||
| 21 | 1 | public static function convertToAnonymous($object) |
|
| 22 | { |
||
| 23 | 1 | $reflection = new \ReflectionClass($object); |
|
| 24 | $class = new class() extends Anonymize { |
||
| 25 | }; |
||
| 26 | |||
| 27 | 1 | $methods = $reflection->getMethods(\ReflectionMethod::IS_PUBLIC); |
|
| 28 | 1 | ||
| 29 | 1 | foreach ($methods as $method) { |
|
| 30 | $closure = $method->getClosure($object); |
||
| 31 | 1 | ||
| 32 | 1 | if ($closure instanceof \Closure) { |
|
| 33 | $class::addDynamicMethod($method->name, $closure); |
||
| 34 | } |
||
| 35 | } |
||
| 36 | 1 | ||
| 37 | 1 | $methods = $reflection->getMethods(\ReflectionMethod::IS_PROTECTED | \ReflectionMethod::IS_PRIVATE); |
|
| 38 | 1 | ||
| 39 | foreach ($methods as $method) { |
||
| 40 | 1 | $closure = $method->getClosure($object); |
|
| 41 | 1 | ||
| 42 | if ($closure instanceof \Closure) { |
||
| 43 | $class::addDynamicMethod($method->name, $closure); |
||
| 44 | } |
||
| 45 | 1 | } |
|
| 46 | 1 | ||
| 47 | 1 | $properties = $reflection->getProperties(\ReflectionProperty::IS_PUBLIC); |
|
| 48 | |||
| 49 | foreach ($properties as $property) { |
||
| 50 | 1 | $class::addDynamicProperty($property->name, $property->getValue($object)); |
|
| 51 | 1 | } |
|
| 52 | 1 | ||
| 53 | 1 | $properties = $reflection->getProperties(\ReflectionProperty::IS_PROTECTED | \ReflectionProperty::IS_PRIVATE); |
|
| 54 | |||
| 55 | foreach ($properties as $property) { |
||
| 56 | 1 | $property->setAccessible(true); |
|
| 57 | $class::addDynamicProperty($property->name, $property->getValue($object)); |
||
| 58 | } |
||
| 59 | |||
| 60 | return $class; |
||
| 61 | } |
||
| 63 |