useTemplateOverride()   B
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 18
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 5.675
Metric Value
dl 0
loc 18
ccs 7
cts 10
cp 0.7
rs 8.8571
cc 5
eloc 13
nc 4
nop 1
crap 5.675
1
<?php
2
3
class PageControllerTemplateOverrideExtension extends Extension
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
4
{
5
    /*
6
    If the alternative template exists, render that, otherwise render with the default template
7
    */
8 3
    public function index()
9
    {
10 3
        return $this->useTemplateOverride();
11
    }
12
13
    /**
14
     * Render this page using the template override iff it exists.
15
     *
16
     * @return array An array suitable for SilverStripe to use the correct template
17
     */
18 3
    public function useTemplateOverride($data = null)
19
    {
20 3
        $template = $this->owner->AlternativeTemplate;
21 3
        if (isset($template) && $template != '') {
22 2
            if ($data) {
23
                return $this->owner->customise(new ArrayData($data))
24
                        ->renderWith(array($this->owner->AlternativeTemplate, $this->owner->ClassName, 'Page'));
25
            } else {
26 2
                return $this->owner->renderWith(array($this->owner->AlternativeTemplate, $this->owner->ClassName, 'Page'));
27
            }
28
        } else {
29 1
            if ($data) {
30
                return $data;
31
            } else {
32 1
                return array();
33
            }
34
        }
35
    }
36
}
37