From 16606da8a19c0b9efbf02442a884d1895fc8c689 Mon Sep 17 00:00:00 2001 From: Bilge Date: Sat, 28 Jan 2017 09:38:01 +0000 Subject: [PATCH] Added DeepCopy to replace __clone implementations. --- composer.json | 1 + src/Porter.php | 32 ++++++++++++++++++++++- src/Specification/ImportSpecification.php | 15 ----------- 3 files changed, 32 insertions(+), 16 deletions(-) diff --git a/composer.json b/composer.json index 8723548..bc06279 100644 --- a/composer.json +++ b/composer.json @@ -14,6 +14,7 @@ "scriptfusion/retry": "^1.1", "scriptfusion/retry-exception-handlers": "^1", "eloquent/enumeration": "^5", + "myclabs/deep-copy": "^1", "psr/cache": "^1", "zendframework/zend-uri": "^2" }, diff --git a/src/Porter.php b/src/Porter.php index 0b2e00f..1f8cf6f 100644 --- a/src/Porter.php +++ b/src/Porter.php @@ -1,6 +1,13 @@ defaultCacheAdvice = CacheAdvice::SHOULD_NOT_CACHE(); + $this->deepCopy = $this->createDeepCopier(); } /** @@ -66,7 +79,9 @@ public function __construct() */ public function import(ImportSpecification $specification) { - $specification = clone $specification; + /** @var ImportSpecification $specification */ + $specification = $this->deepCopy->copy($specification); + $records = $this->fetch($specification->getResource(), $specification->getCacheAdvice()); if (!$records instanceof ProviderRecords) { @@ -316,4 +331,19 @@ public function setFetchExceptionHandler(callable $fetchExceptionHandler) { $this->fetchExceptionHandler = $fetchExceptionHandler; } + + /** + * @return DeepCopy + */ + private function createDeepCopier() + { + $copier = new DeepCopy; + + // Enumerations are immutable thus do not require cloning. + $copier->addFilter(new KeepFilter, new PropertyTypeMatcher(MultitonInterface::class)); + + $copier->addTypeFilter(new ShallowCopyFilter, new TypeMatcher(MockInterface::class)); + + return $copier; + } } diff --git a/src/Specification/ImportSpecification.php b/src/Specification/ImportSpecification.php index 0dbf96a..ecc04b5 100644 --- a/src/Specification/ImportSpecification.php +++ b/src/Specification/ImportSpecification.php @@ -36,21 +36,6 @@ public function __construct(ProviderResource $resource) $this->clearTransformers(); } - public function __clone() - { - $this->resource = clone $this->resource; - - $transformers = $this->transformers; - $this->clearTransformers()->addTransformers(array_map( - function (Transformer $transformer) { - return clone $transformer; - }, - $transformers - )); - - is_object($this->context) && $this->context = clone $this->context; - } - /** * @return ProviderResource */