DataFilterEagerLoadingExtension   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 16
c 1
b 0
f 0
dl 0
loc 26
ccs 16
cts 16
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A with() 0 21 4
1
<?php
2
namespace Gurucomkz\EagerLoading;
3
4
use SilverStripe\ORM\DataExtension;
5
6
/**
7
 *
8
 * @property-read \SilverStripe\ORM\DataList $owner
9
 *
10
 */
11
class DataFilterEagerLoadingExtension extends DataExtension
12
{
13
14
    public $withList = [];
15
    public $withListOriginal = [];
16 12
    public function with($list)
17
    {
18
        // return $this->owner;
19 12
        if (!isset($this->owner->withList)) {
20 12
            $this->owner->withList = [];
21
        }
22 12
        if (!isset($this->owner->withListOriginal)) {
23 12
            $this->owner->withListOriginal = [];
24
        }
25 12
        if (!is_array($list)) {
26 9
            $list = [$list];
27
        }
28 12
        $this->owner->withListOriginal = $list;
29 12
        $list = array_map(
30 12
            function ($e) {
31 12
                return explode('.', $e);
32 12
            },
33 12
            $list
34 12
        );
35 12
        $this->owner->withList = array_merge($this->owner->withList, $list);
36 12
        return EagerLoadedDataList::cloneFrom($this->owner);
37
    }
38
}
39