Passed
Push — master ( c4e2cf...d0ece3 )
by Tim
04:07
created

AmpPagesControllerExtension::addAmpStyles()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 8
nc 3
nop 0
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
1
<?php
2
namespace DorsetDigital\SilverStripeAmpPages;
3
4
use SilverStripe\Core\Extension;
5
use SilverStripe\Control\Controller;
6
use SilverStripe\View\Requirements;
7
8
class AmpPagesControllerExtension extends Extension
9
{
10
11
    private static $allowed_actions = ['amp'];
0 ignored issues
show
introduced by
The private property $allowed_actions is not used, and could be removed.
Loading history...
12
13
    public function amp()
14
    {
15
        Requirements::clear();
16
        $this->addAmpStyles();
17
        $controller = Controller::curr();
18
        $class = $controller->ClassName;
19
        return $this->owner->renderWith([$class."_amp", "Amp"]);
20
    }
21
22
    private function addAmpStyles()
23
    {
24
        $css = null;
25
        $cssFiles = AmpPagesRequirementsExtension::getAmpCSSFiles();
26
        foreach ($cssFiles as $themeCSSPath) {
27
            $fullCSSPath = BASE_PATH.DIRECTORY_SEPARATOR.$themeCSSPath;
28
            if (is_file($fullCSSPath)) {
29
                $css .= file_get_contents($fullCSSPath);
30
            }
31
        }
32
        $tag = '<style amp-custom>'.$css.'</style>';
33
        Requirements::insertHeadTags($tag);
34
    }
35
}
36