Completed
Pull Request — master (#3)
by
unknown
03:57
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
7
class Cloner
8
{
9
    private $cloneService;
10
    private $persistenceService;
11
12
    /**
13
     * @param CloneServiceInterface $cloneService
14
     * @param PersistenceServiceInterface $persistenceService
15
     */
16 8
    public function __construct(CloneServiceInterface $cloneService, PersistenceServiceInterface $persistenceService)
17
    {
18 8
        $this->cloneService = $cloneService;
19 8
        $this->persistenceService = $persistenceService;
20 8
    }
21
22
    /**
23
     * Clone a model without persisting it
24
     *
25
     * @param $model
26
     * @return Model
27
     */
28 4
    public function clone($model): Model
29
    {
30 4
        return $this->cloneService->clone($model);
31
    }
32
33
    /**
34
     * Persist a cloned model
35
     *
36
     * @param $model
37
     * @return Model
38
     */
39 4
    public function persist($model): Model
40
    {
41 4
        return $this->persistenceService->persist($model);
42
    }
43
44
    /**
45
     * Clone and persist a model
46
     *
47
     * @param $model
48
     * @return Model
49
     */
50 2
    public function cloneAndPersist($model) : Model
51
    {
52 2
        return $this->persist($this->clone($model));
53
    }
54
55
    /**
56
     * Retrieve the map of original keys to cloned keys
57
     *
58
     * @return array
59
     */
60
    public function getKeyMap() : array
61
    {
62
        return $this->cloneService->getKeyMap();
0 ignored issues
show
Bug introduced by
The method getKeyMap() does not exist on Anfischer\Cloner\CloneServiceInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to Anfischer\Cloner\CloneServiceInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

62
        return $this->cloneService->/** @scrutinizer ignore-call */ getKeyMap();
Loading history...
63
    }
64
}
65