From 3dcf48e7ceacf46896e16afb22e9e2a92dde5e76 Mon Sep 17 00:00:00 2001 From: klkvsk Date: Mon, 20 Feb 2023 19:36:41 +0300 Subject: [PATCH] use spatie cloneable (pr approved) --- composer.json | 3 ++- src/Helpers/Cloneable.php | 41 ----------------------------------- src/Schema/AbstractObject.php | 2 +- 3 files changed, 3 insertions(+), 43 deletions(-) delete mode 100644 src/Helpers/Cloneable.php diff --git a/composer.json b/composer.json index 35a94d0..e52d332 100644 --- a/composer.json +++ b/composer.json @@ -33,7 +33,8 @@ "opis/closure": "^3.6", "psr/log": "^3.0", "ulrichsg/getopt-php": "^4.0", - "splitbrain/php-cli": "^1.2" + "splitbrain/php-cli": "^1.2", + "spatie/php-cloneable": "^1.0.1" }, "require-dev": { "friendsofphp/php-cs-fixer": "^3.14", diff --git a/src/Helpers/Cloneable.php b/src/Helpers/Cloneable.php deleted file mode 100644 index 5e5d7d2..0000000 --- a/src/Helpers/Cloneable.php +++ /dev/null @@ -1,41 +0,0 @@ -newInstanceWithoutConstructor(); - - foreach (get_object_vars($this) as $objectField => $objectValue) { - $objectValue = array_key_exists($objectField, $values) ? $values[$objectField] : $objectValue; - - $declarationScope = $ref->getProperty($objectField)->getDeclaringClass()->getName(); - if ($declarationScope == self::class) { - $clone->$objectField = $objectValue; - } else { - (fn () => $this->$objectField = $objectValue) - ->bindTo($clone, $declarationScope)(); - } - } - - if (method_exists($clone, '__clone')) { - $clone = clone $clone; - } - return $clone; - } catch (ReflectionException $e) { - throw new SchemaException('Could not clone ' . get_class($this), 0, $e); - } - } -} diff --git a/src/Schema/AbstractObject.php b/src/Schema/AbstractObject.php index 755c3f9..fdd4482 100644 --- a/src/Schema/AbstractObject.php +++ b/src/Schema/AbstractObject.php @@ -4,7 +4,7 @@ namespace Klkvsk\DtoGenerator\Schema; use Klkvsk\DtoGenerator\Exception\SchemaException; -use Klkvsk\DtoGenerator\Helpers\Cloneable; +use Spatie\Cloneable\Cloneable; abstract class AbstractObject {