Passed
Pull Request — master (#279)
by Robbie
02:19 queued 21s
created

SiteTreeExtension   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 11
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 11
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A ElementArea() 0 4 2
1
<?php
2
3
namespace DNADesign\Elemental\Extensions;
4
5
use DNADesign\Elemental\Models\ElementalArea;
6
use SilverStripe\ORM\DataExtension;
7
8
/**
9
 * The SiteTreeExtension provides a consistent API surface for reading elements from pages regardless
10
 * of whether the specific implementation of SiteTree (subclass) has the elemental extension applied.
11
 */
12
class SiteTreeExtension extends DataExtension
13
{
14
    /**
15
     * Returns the owner's `ElementalArea()` contents if it has the extension
16
     *
17
     * @return ElementalArea|null
18
     */
19
    public function ElementArea()
20
    {
21
        if ($this->owner->hasExtension(ElementalPageExtension::class)) {
22
            return $this->owner->ElementalArea();
23
        }
24
    }
25
}
26