Passed
Push — v1 ( eca0e2...a307d6 )
by Andrew
07:27 queued 04:35
created

Beacons::includeAmpHtmlBeacon()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 14
rs 10
c 0
b 0
f 0
cc 1
nc 1
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
        $boomerangUrl = Craft::$app->assetManager->getPublishedUrl(
44
            '@nystudio107/webperf/assetbundles/boomerang/dist/js/boomerang-1.0.0.min.js',
45
            true
46
        );
47
        $script = PluginTemplate::renderPluginTemplate(
48
            '_frontend/scripts/load-boomerang-iframe.twig',
49
            [
50
                'boomerangScriptUrl' => $boomerangUrl,
51
            ]
52
        );
53
        $view->registerJs(
54
            $script,
55
            $view::POS_HEAD
56
        );
57
    }
58
59
    /*
60
     * @return void
61
     */
62
    public function includeAmpHtmlScript()
0 ignored issues
show
Coding Style introduced by
You must use "/**" style comments for a function comment
Loading history...
63
    {
64
        $view = Craft::$app->getView();
65
        $view->registerJsFile(
66
            self::AMP_IFRAME_SCRIPT_URL,
67
            [
68
                'position' => $view::POS_HEAD,
69
                'async' => 'async',
70
                'custom-element' => 'amp-iframe',
71
            ],
72
            'webperf-amp-iframe-script'
73
        );
74
    }
75
76
    /*
77
     * @return void
78
     */
79
    public function includeAmpHtmlBeacon()
0 ignored issues
show
Coding Style introduced by
You must use "/**" style comments for a function comment
Loading history...
80
    {
81
        $view = Craft::$app->getView();
0 ignored issues
show
Unused Code introduced by
The assignment to $view is dead and can be removed.
Loading history...
82
        $boomerangUrl = Craft::$app->assetManager->getPublishedUrl(
83
            '@nystudio107/webperf/assetbundles/boomerang/dist/js/boomerang-1.0.0.min.js',
84
            true
85
        );
86
        $html = PluginTemplate::renderPluginTemplate(
87
            '_frontend/scripts/load-boomerang-amp-iframe.twig',
88
            [
89
                'boomerangScriptUrl' => $boomerangUrl,
90
            ]
91
        );
92
        echo $html;
93
    }
94
}
95