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

ObjectFromUserMutator::getElement()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 0
cts 13
cp 0
rs 9.7333
c 0
b 0
f 0
cc 4
nc 4
nop 0
crap 20
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