Completed
Pull Request — master (#3)
by
unknown
03:33
created

Cloner::getKeyMap()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 0
cp 0
crap 2
rs 10
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 8
     */
17
    public function __construct(CloneServiceInterface $cloneService, PersistenceServiceInterface $persistenceService)
18 8
    {
19 8
        $this->cloneService = $cloneService;
20 8
        $this->persistenceService = $persistenceService;
21
    }
22
23
    /**
24
     * Clone a model without persisting it
25
     *
26
     * @param $model
27
     * @return Model
28 4
     */
29
    public function clone($model): Model
30 4
    {
31
        return $this->cloneService->clone($model);
32
    }
33
34
    /**
35
     * Persist a cloned model
36
     *
37
     * @param $model
38
     * @return Model
39 4
     */
40
    public function persist($model): Model
41 4
    {
42
        return $this->persistenceService->persist($model);
43
    }
44
45
    /**
46
     * Clone and persist a model
47
     *
48
     * @param $model
49
     * @return Model
50 2
     */
51
    public function cloneAndPersist($model) : Model
52 2
    {
53
        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
    public function getKeyMap(): Collection
62
    {
63
        return $this->cloneService->getKeyMap();
64
    }
65
}
66