diff --git a/src/Cloner.php b/src/Cloner.php index 3a2932c..6f57388 100644 --- a/src/Cloner.php +++ b/src/Cloner.php @@ -1,14 +1,13 @@ attachment = $attachment; $this->events = $events; } @@ -45,8 +42,7 @@ public function __construct( * @param Illuminate\Database\Eloquent\Relations\Relation $relation * @return Illuminate\Database\Eloquent\Model The new model instance */ - public function duplicate($model, $relation = null) - { + public function duplicate($model, $relation = null) { $clone = $this->cloneModel($model); $this->duplicateAttachments($clone); $this->saveClone($clone, $relation, $model); @@ -61,8 +57,7 @@ public function duplicate($model, $relation = null) * @param string $connection A Laravel database connection * @return Illuminate\Database\Eloquent\Model The new model instance */ - public function duplicateTo($model, $connection) - { + public function duplicateTo($model, $connection) { $this->write_connection = $connection; // Store the write database connection $clone = $this->duplicate($model); // Do a normal duplicate $this->write_connection = null; // Null out the connection for next run @@ -75,8 +70,7 @@ public function duplicateTo($model, $connection) * @param Illuminate\Database\Eloquent\Model $model * @return Illuminate\Database\Eloquent\Model The new model instance */ - protected function cloneModel($model) - { + protected function cloneModel($model) { $exempt = method_exists($model, 'getCloneExemptAttributes') ? $model->getCloneExemptAttributes() : null; $clone = $model->replicate($exempt); @@ -91,10 +85,9 @@ protected function cloneModel($model) * @param Illuminate\Database\Eloquent\Model $clone * @return void */ - protected function duplicateAttachments($clone) - { + protected function duplicateAttachments($clone) { if (!$this->attachment || !method_exists($clone, 'getCloneableFileAttributes')) return; - foreach ($clone->getCloneableFileAttributes() as $attribute) { + foreach($clone->getCloneableFileAttributes() as $attribute) { if (!$original = $clone->getAttribute($attribute)) continue; $clone->setAttribute($attribute, $this->attachment->duplicate($original)); } @@ -110,15 +103,14 @@ protected function duplicateAttachments($clone) * @param boolean $child * @return void */ - protected function saveClone($clone, $relation = null, $src, $child = null) - { + protected function saveClone($clone, $relation = null, $src, $child = null) { // Set the child flag if ($relation) $child = true; // Notify listeners via callback or event if (method_exists($clone, 'onCloning')) $clone->onCloning($src, $child); - $this->events->dispatch('cloner::cloning: ' . get_class($src), [$clone, $src]); + $this->events->dispatch('cloner::cloning: '.get_class($src), [$clone, $src]); // Do the save if ($relation) $relation->save($clone); @@ -126,7 +118,7 @@ protected function saveClone($clone, $relation = null, $src, $child = null) // Notify listeners via callback or event if (method_exists($clone, 'onCloned')) $clone->onCloned($src); - $this->events->dispatch('cloner::cloned: ' . get_class($src), [$clone, $src]); + $this->events->dispatch('cloner::cloned: '.get_class($src), [$clone, $src]); } /** @@ -136,10 +128,9 @@ protected function saveClone($clone, $relation = null, $src, $child = null) * @param Illuminate\Database\Eloquent\Model $clone * @return void */ - protected function cloneRelations($model, $clone) - { + protected function cloneRelations($model, $clone) { if (!method_exists($model, 'getCloneableRelations')) return; - foreach ($model->getCloneableRelations() as $relation_name) { + foreach($model->getCloneableRelations() as $relation_name) { $this->duplicateRelation($model, $relation_name, $clone); } } @@ -152,8 +143,7 @@ protected function cloneRelations($model, $clone) * @param Illuminate\Database\Eloquent\Model $clone * @return void */ - protected function duplicateRelation($model, $relation_name, $clone) - { + protected function duplicateRelation($model, $relation_name, $clone) { $relation = call_user_func([$model, $relation_name]); if (is_a($relation, 'Illuminate\Database\Eloquent\Relations\BelongsToMany')) { $this->duplicatePivotedRelation($relation, $relation_name, $clone); @@ -169,8 +159,7 @@ protected function duplicateRelation($model, $relation_name, $clone) * @param Illuminate\Database\Eloquent\Model $clone * @return void */ - protected function duplicatePivotedRelation($relation, $relation_name, $clone) - { + protected function duplicatePivotedRelation($relation, $relation_name, $clone) { // If duplicating between databases, do not duplicate relations. The related // instance may not exist in the other database or could have a different @@ -198,9 +187,8 @@ protected function duplicatePivotedRelation($relation, $relation_name, $clone) * @param Illuminate\Database\Eloquent\Model $clone * @return void */ - protected function duplicateDirectRelation($relation, $relation_name, $clone) - { - $relation->get()->each(function ($foreign) use ($clone, $relation_name) { + protected function duplicateDirectRelation($relation, $relation_name, $clone) { + $relation->get()->each(function($foreign) use ($clone, $relation_name) { $this->duplicate($foreign, $clone->$relation_name()); }); }