PrevNextSiblingExtension   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 13
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 6
c 1
b 0
f 0
dl 0
loc 13
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A NextSibling() 0 5 1
A PreviousSibling() 0 4 1
1
<?php
2
3
namespace WebOfTalent\PrevNextSibling;
4
5
use SilverStripe\CMS\Model\SiteTree;
6
use SilverStripe\Core\Extension;
7
8
class PrevNextSiblingExtension extends Extension
9
{
10
    public function NextSibling()
11
    {
12
        $where = "\"ParentID\" = {$this->owner->ParentID} AND \"Sort\" > {$this->owner->Sort}";
13
        $result = SiteTree::get()->where($where)->sort('"Sort"')->First();
14
        return $result;
15
    }
16
17
    public function PreviousSibling()
18
    {
19
        $where = "\"ParentID\" = {$this->owner->ParentID} AND \"Sort\" < {$this->owner->Sort}";
20
        return SiteTree::get()->where($where)->sort('"Sort" DESC')->First();
21
    }
22
}
23