ElementByString   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 2
dl 0
loc 56
ccs 0
cts 26
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A find() 0 13 3
A findCache() 0 13 3
A addToCache() 0 9 1
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
     * @inheritdoc
45
     */
46
    public function findCache($identifier, int $siteId = null)
47
    {
48
49
        if ($model = parent::findCache($identifier)) {
50
            return $model;
51
        }
52
53
        if (!is_string($identifier)) {
54
            return null;
55
        }
56
57
        return $this->findCacheByString($identifier);
58
    }
59
60
    /**
61
     * @inheritdoc
62
     */
63
    public function addToCache(ElementInterface $element)
64
    {
65
66
        parent::addToCache($element);
67
68
        $this->cacheByString($element);
69
70
        return $this;
71
    }
72
}
73