Cloner   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 56
ccs 11
cts 11
cp 1
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A cloneAndPersist() 0 3 1
A getKeyMap() 0 3 1
A persist() 0 3 1
A clone() 0 3 1
1
<?php
2
3
namespace Anfischer\Cloner;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Support\Collection;
7
8
class Cloner
9
{
10
    private $cloneService;
11
    private $persistenceService;
12
13
    /**
14
     * @param CloneServiceInterface $cloneService
15
     * @param PersistenceServiceInterface $persistenceService
16
     */
17 10
    public function __construct(CloneServiceInterface $cloneService, PersistenceServiceInterface $persistenceService)
18
    {
19 10
        $this->cloneService = $cloneService;
20 10
        $this->persistenceService = $persistenceService;
21
    }
22
23
    /**
24
     * Clone a model without persisting it
25
     *
26
     * @param $model
27
     * @return Model
28
     */
29 4
    public function clone($model): Model
30
    {
31 4
        return $this->cloneService->clone($model);
32
    }
33
34
    /**
35
     * Persist a cloned model
36
     *
37
     * @param $model
38
     * @return Model
39
     */
40 4
    public function persist($model): Model
41
    {
42 4
        return $this->persistenceService->persist($model);
43
    }
44
45
    /**
46
     * Clone and persist a model
47
     *
48
     * @param $model
49
     * @return Model
50
     */
51 2
    public function cloneAndPersist($model) : Model
52
    {
53 2
        return $this->persist($this->clone($model));
54
    }
55
56
    /**
57
     * Retrieve the map of original keys to cloned keys
58
     *
59
     * @return Collection
60
     */
61 2
    public function getKeyMap(): Collection
62
    {
63 2
        return $this->cloneService->getKeyMap();
64
    }
65
}
66