Completed
Push — develop ( 66c9da...653b7b )
by Nate
02:53
created

FieldAttributeTrait::resolveFieldStringValue()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 7
cp 0
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 6
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://github.com/flipboxfactory/craft-ember/blob/master/LICENSE
6
 * @link       https://github.com/flipboxfactory/craft-ember/
7
 */
8
9
namespace flipbox\craft\ember\queries;
10
11
use Craft;
12
use craft\base\Field;
13
use craft\base\FieldInterface;
14
use flipbox\craft\ember\helpers\QueryHelper;
15
16
/**
17
 * @author Flipbox Factory <[email protected]>
18
 * @since 2.0.0
19
 */
20
trait FieldAttributeTrait
21
{
22
    /**
23
     * The field(s) that the resulting organizations’ fields must have.
24
     *
25
     * @var string|string[]|int|int[]|FieldInterface|FieldInterface[]|null
26
     */
27
    public $field;
28
29
    /**
30
     * @param string|string[]|int|int[]|FieldInterface|FieldInterface[]|null $value
31
     * @return static The query object
32
     */
33
    public function setField($value)
34
    {
35
        $this->field = $value;
36
        return $this;
37
    }
38
39
    /**
40
     * @param string|string[]|int|int[]|FieldInterface|FieldInterface[]|null $value
41
     * @return static The query object
42
     */
43
    public function field($value)
44
    {
45
        return $this->setField($value);
46
    }
47
48
    /**
49
     * @param string|string[]|int|int[]|FieldInterface|FieldInterface[]|null $value
50
     * @return static The query object
51
     */
52
    public function setFieldId($value)
53
    {
54
        return $this->setField($value);
55
    }
56
57
    /**
58
     * @param string|string[]|int|int[]|FieldInterface|FieldInterface[]|null $value
59
     * @return static The query object
60
     */
61
    public function fieldId($value)
62
    {
63
        return $this->setField($value);
64
    }
65
66
    /**
67
     * @param $value
68
     * @return array|string
69
     */
70
    protected function parseFieldValue($value)
71
    {
72
        return QueryHelper::prepareParam(
73
            $value,
74
            function(string $handle) {
75
                return Craft::$app->getFields()->getFieldByHandle($handle);
76
            }
77
        );
78
    }
79
}
80