PageControllerTemplateOverrideExtension   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 75%
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 34
ccs 9
cts 12
cp 0.75
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A index() 0 4 1
B useTemplateOverride() 0 18 5
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