CategoryList::resolveElement()   A
last analyzed

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-element-lists/LICENSE
6
 * @link       https://github.com/flipboxfactory/craft-element-lists/
7
 */
8
9
namespace flipbox\craft\element\lists\fields;
10
11
use craft\elements\Category;
12
use craft\fields\Categories;
13
use flipbox\craft\element\lists\ElementList;
14
15
/**
16
 * @author Flipbox Factory <[email protected]>
17
 * @since 1.0.0
18
 */
19
class CategoryList extends Categories implements SortableInterface, RelationalInterface
20
{
21
    use ElementListTrait;
22
23
    /**
24
     * @inheritdoc
25
     */
26
    public static function displayName(): string
27
    {
28
        return ElementList::t('Category List');
29
    }
30
31
    /**
32
     * @inheritdoc
33
     */
34
    public function settingsAttributes(): array
35
    {
36
        return array_merge(
37
            parent::settingsAttributes(),
38
            [
39
                'sortable'
40
            ]
41
        );
42
    }
43
44
    /**
45
     * @inheritDoc
46
     * @return Category|null
47
     */
48
    public function resolveElement($element)
49
    {
50
        if (is_numeric($element)) {
51
            return \Craft::$app->getCategories()->getCategoryById($element);
52
        }
53
54
        return Category::findOne($element);
0 ignored issues
show
Bug Compatibility introduced by
The expression \craft\elements\Category::findOne($element); of type craft\base\Element|null|craft\base\Element[] adds the type craft\base\Element[] to the return on line 54 which is incompatible with the return type declared by the interface flipbox\craft\element\li...terface::resolveElement of type craft\base\ElementInterface|null.
Loading history...
55
    }
56
}
57