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

ElementByString::findByString()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 24
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 8.9713
c 0
b 0
f 0
nc 3
cc 3
eloc 7
nop 2
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 craft\base\ElementInterface;
12
13
/**
14
 * @author Flipbox Factory <[email protected]>
15
 * @since 1.0.0
16
 */
17
abstract class ElementByString extends Element
18
{
19
20
    use traits\ElementByString;
21
22
    /*******************************************
23
     * FIND
24
     *******************************************/
25
26
    /**
27
     * @inheritdoc
28
     */
29
    public function find($identifier, int $siteId = null)
30
    {
31
32
        if ($model = parent::find($identifier, $siteId)) {
33
            return $model;
34
        }
35
36
        if (!is_string($identifier)) {
37
            return null;
38
        }
39
40
        return $this->findByString($identifier, $siteId);
41
42
    }
43
44
    /**
45
     * @inheritdoc
46
     */
47 View Code Duplication
    public function findCache($identifier, int $siteId = 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...
48
    {
49
50
        if ($model = parent::findCache($identifier)) {
51
            return $model;
52
        }
53
54
        if (!is_string($identifier)) {
55
            return null;
56
        }
57
58
        return $this->findCacheByString($identifier);
59
60
    }
61
62
    /**
63
     * @inheritdoc
64
     */
65
    public function addToCache(ElementInterface $element)
66
    {
67
68
        parent::addToCache($element);
69
70
        $this->cacheByString($element);
71
72
        return $this;
73
74
    }
75
76
}
77