Passed
Push — master ( f2dea1...58a092 )
by Nate
04:47
created

ObjectByString   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 75
Duplicated Lines 37.33 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 9
lcom 0
cbo 2
dl 28
loc 75
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A find() 14 14 3
A findCache() 14 14 3
A addToCache() 0 10 1
A findCacheByRecord() 0 10 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://github.com/flipbox/spark/blob/master/LICENSE
6
 * @link       https://github.com/flipbox/spark
7
 */
8
9
namespace flipbox\spark\services;
10
11
use flipbox\spark\records\Record;
12
use yii\base\Object as BaseObject;
13
14
/**
15
 * @author Flipbox Factory <[email protected]>
16
 * @since 1.0.0
17
 */
18
abstract class ObjectByString extends Object
19
{
20
21
    use traits\ObjectByString;
22
23
    /**
24
     * @inheritdoc
25
     */
26 View Code Duplication
    public function find($identifier, string $toScenario = null)
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
27
    {
28
29
        if ($model = parent::find($identifier, $toScenario)) {
30
            return $model;
31
        }
32
33
        if (!is_string($identifier)) {
34
            return null;
35
        }
36
37
        return $this->findByString($identifier, $toScenario);
38
39
    }
40
41
    /*******************************************
42
     * CACHE
43
     *******************************************/
44
45
    /**
46
     * @inheritdoc
47
     */
48 View Code Duplication
    public function findCache($identifier)
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
49
    {
50
51
        if ($model = parent::findCache($identifier)) {
52
            return $model;
53
        }
54
55
        if (!is_string($identifier)) {
56
            return null;
57
        }
58
59
        return $this->findCacheByString($identifier);
60
61
    }
62
63
    /**
64
     * @inheritdoc
65
     */
66
    public function addToCache(BaseObject $object)
67
    {
68
69
        parent::addToCache($object);
70
71
        $this->cacheByString($object);
72
73
        return $this;
74
75
    }
76
77
78
    /**
79
     * @inheritdoc
80
     */
81
    public function findCacheByRecord(Record $record)
82
    {
83
84
        if ($model = parent::findCacheByRecord($record)) {
85
            return $model;
86
        }
87
88
        return $this->findCacheByRecordByString($record);
89
90
    }
91
92
}
93