Passed
Pull Request — master (#279)
by Robbie
03:50
created

SiteTreeExtension::ElementalAreaIfExists()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
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 ElementalAreaIfExists()
20
    {
21
        if ($this->owner->hasExtension(ElementalPageExtension::class)) {
22
            return $this->owner->ElementalArea();
23
        }
24
    }
25
}
26