for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace drupol\Anonymize;
/**
* Trait AnonymizeTrait.
*/
trait AnonymizeTrait
{
* Convert an object into an anonymous object.
*
* @param object $object
* @throws \ReflectionException
* @return Anonymize
public static function convertToAnonymous($object)
$reflection = new \ReflectionClass($object);
$class = new class() extends Anonymize {
};
$methods = $reflection->getMethods(\ReflectionMethod::IS_PUBLIC);
foreach ($methods as $method) {
$closure = $method->getClosure($object);
if ($closure instanceof \Closure) {
$class::addDynamicMethod($method->name, $closure);
}
$methods = $reflection->getMethods(\ReflectionMethod::IS_PROTECTED | \ReflectionMethod::IS_PRIVATE);
$properties = $reflection->getProperties(\ReflectionProperty::IS_PUBLIC);
foreach ($properties as $property) {
$class::addDynamicProperty($property->name, $property->getValue($object));
$properties = $reflection->getProperties(\ReflectionProperty::IS_PROTECTED | \ReflectionProperty::IS_PRIVATE);
$property->setAccessible(true);
return $class;