Completed
Push — develop ( de31bd...3158f9 )
by Nate
20:35
created

ObjectFromUserMutator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 23
ccs 0
cts 13
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getElement() 0 16 4
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://flipboxfactory.com/software/hubspot/license
6
 * @link       https://www.flipboxfactory.com/software/hubspot/
7
 */
8
9
namespace flipbox\hubspot\criteria\element;
10
11
use Craft;
12
use craft\base\ElementInterface;
13
use craft\errors\ElementNotFoundException;
14
15
/**
16
 * @author Flipbox Factory <[email protected]>
17
 * @since 1.0.0
18
 */
19
class ObjectFromUserMutator extends ObjectFromElementMutator
20
{
21
    /**
22
     * @return ElementInterface
23
     * @throws ElementNotFoundException
24
     */
25
    protected function getElement(): ElementInterface
26
    {
27
        if ($this->element instanceof ElementInterface) {
28
            return $this->element;
29
        }
30
31
        if (is_numeric($this->element)) {
32
            return $this->element = Craft::$app->getUsers()->getUserById($this->element);
33
        }
34
35
        if (is_string($this->element)) {
36
            return $this->element = Craft::$app->getUsers()->getUserByUsernameOrEmail($this->element);
37
        }
38
39
        throw new ElementNotFoundException("Unable to resolve element.");
40
    }
41
}
42