Passed
Push — develop ( eca0e2...869046 )
by Andrew
03:00
created

Beacons::includeAmpHtmlBeacon()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 20
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 20
rs 9.8666
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
/**
3
 * Webperf plugin for Craft CMS 3.x
4
 *
5
 * Monitor the performance of your webpages through real-world user timing data
6
 *
7
 * @link      https://nystudio107.com
0 ignored issues
show
Coding Style introduced by
The tag in position 1 should be the @copyright tag
Loading history...
8
 * @copyright Copyright (c) 2018 nystudio107
0 ignored issues
show
Coding Style introduced by
@copyright tag must contain a year and the name of the copyright holder
Loading history...
9
 */
0 ignored issues
show
Coding Style introduced by
PHP version not specified
Loading history...
Coding Style introduced by
Missing @category tag in file comment
Loading history...
Coding Style introduced by
Missing @package tag in file comment
Loading history...
Coding Style introduced by
Missing @author tag in file comment
Loading history...
Coding Style introduced by
Missing @license tag in file comment
Loading history...
10
11
namespace nystudio107\webperf\services;
12
13
use nystudio107\webperf\Webperf;
14
use nystudio107\webperf\helpers\PluginTemplate;
15
use nystudio107\webperf\assetbundles\boomerang\BoomerangAsset;
16
17
use Craft;
0 ignored issues
show
Bug introduced by
The type Craft was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
18
use craft\base\Component;
0 ignored issues
show
Bug introduced by
The type craft\base\Component was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
19
20
use yii\base\InvalidConfigException;
0 ignored issues
show
Bug introduced by
The type yii\base\InvalidConfigException was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
21
22
/**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
23
 * @author    nystudio107
0 ignored issues
show
Coding Style introduced by
The tag in position 1 should be the @package tag
Loading history...
Coding Style introduced by
Content of the @author tag must be in the form "Display Name <[email protected]>"
Loading history...
Coding Style introduced by
Tag value indented incorrectly; expected 2 spaces but found 4
Loading history...
24
 * @package   Webperf
0 ignored issues
show
Coding Style introduced by
Tag value indented incorrectly; expected 1 spaces but found 3
Loading history...
25
 * @since     1.0.0
0 ignored issues
show
Coding Style introduced by
The tag in position 3 should be the @author tag
Loading history...
Coding Style introduced by
Tag value indented incorrectly; expected 3 spaces but found 5
Loading history...
26
 */
0 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
27
class Beacons extends Component
28
{
29
    // Constants
30
    // =========================================================================
31
32
    const AMP_IFRAME_SCRIPT_URL = "https://cdn.ampproject.org/v0/amp-iframe-0.1.js";
33
34
    // Public Methods
35
    // =========================================================================
36
37
    /*
38
     * @return void
39
     */
40
    public function includeHtmlBeacon()
0 ignored issues
show
Coding Style introduced by
You must use "/**" style comments for a function comment
Loading history...
41
    {
42
        $view = Craft::$app->getView();
43
        // Asset bundle
44
        try {
45
            $view->registerAssetBundle(BoomerangAsset::class);
46
        } catch (InvalidConfigException $e) {
47
            Craft::error($e->getMessage(), __METHOD__);
48
        }
49
        $boomerangUrl = Craft::$app->assetManager->getPublishedUrl(
50
            '@nystudio107/webperf/assetbundles/boomerang/dist/js/boomerang-1.0.0.min.js',
51
            true
52
        );
53
        $script = PluginTemplate::renderPluginTemplate(
54
            '_frontend/scripts/load-boomerang-iframe.twig',
55
            [
56
                'boomerangScriptUrl' => $boomerangUrl,
57
            ]
58
        );
59
        $view->registerJs(
60
            $script,
61
            $view::POS_HEAD
62
        );
63
    }
64
65
    /*
66
     * @return void
67
     */
68
    public function includeAmpHtmlScript()
0 ignored issues
show
Coding Style introduced by
You must use "/**" style comments for a function comment
Loading history...
69
    {
70
        $view = Craft::$app->getView();
71
        $view->registerJsFile(
72
            self::AMP_IFRAME_SCRIPT_URL,
73
            [
74
                'async' => 'async',
75
                'custom-element' => 'amp-iframe',
76
            ],
77
            'webperf-amp-iframe-script'
78
        );
79
    }
80
81
    /*
82
     * @return void
83
     */
84
    public function includeAmpHtmlBeacon()
0 ignored issues
show
Coding Style introduced by
You must use "/**" style comments for a function comment
Loading history...
85
    {
86
        $view = Craft::$app->getView();
87
        // Asset bundle
88
        try {
89
            $view->registerAssetBundle(BoomerangAsset::class);
90
        } catch (InvalidConfigException $e) {
91
            Craft::error($e->getMessage(), __METHOD__);
92
        }
93
        $boomerangUrl = Craft::$app->assetManager->getPublishedUrl(
94
            '@nystudio107/webperf/assetbundles/boomerang/dist/js/boomerang-1.0.0.min.js',
95
            true
96
        );
97
        $html = PluginTemplate::renderPluginTemplate(
98
            '_frontend/scripts/load-boomerang-amp-iframe.twig',
99
            [
100
                'boomerangScriptUrl' => $boomerangUrl,
101
            ]
102
        );
103
        echo $html;
104
    }
105
}
106