Passed
Push — v1 ( a307d6...2cba86 )
by Andrew
07:13 queued 03:19
created

Beacons::ampHtmlIframe()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
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\helpers\PluginTemplate;
14
15
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...
16
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...
17
use craft\helpers\UrlHelper;
0 ignored issues
show
Bug introduced by
The type craft\helpers\UrlHelper 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
19
/**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
20
 * @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...
21
 * @package   Webperf
0 ignored issues
show
Coding Style introduced by
Tag value indented incorrectly; expected 1 spaces but found 3
Loading history...
22
 * @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...
23
 */
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...
24
class Beacons extends Component
25
{
26
    // Constants
27
    // =========================================================================
28
29
    const AMP_IFRAME_SCRIPT_URL = "https://cdn.ampproject.org/v0/amp-iframe-0.1.js";
30
31
    // Public Methods
32
    // =========================================================================
33
34
    /*
35
     * @return void
36
     */
37
    public function includeHtmlBeacon()
0 ignored issues
show
Coding Style introduced by
You must use "/**" style comments for a function comment
Loading history...
38
    {
39
        $view = Craft::$app->getView();
40
        $boomerangUrl = Craft::$app->assetManager->getPublishedUrl(
41
            '@nystudio107/webperf/assetbundles/boomerang/dist/js/boomerang-1.0.0.min.js',
42
            true
43
        );
44
        $script = PluginTemplate::renderPluginTemplate(
45
            '_frontend/scripts/load-boomerang-iframe.twig',
46
            [
47
                'boomerangScriptUrl' => $boomerangUrl,
48
            ]
49
        );
50
        $view->registerJs(
51
            $script,
52
            $view::POS_HEAD
53
        );
54
    }
55
56
    /*
57
     * @return void
58
     */
59
    public function includeAmpHtmlScript()
0 ignored issues
show
Coding Style introduced by
You must use "/**" style comments for a function comment
Loading history...
60
    {
61
        $view = Craft::$app->getView();
62
        $view->registerJsFile(
63
            self::AMP_IFRAME_SCRIPT_URL,
64
            [
65
                'position' => $view::POS_HEAD,
66
                'async' => 'async',
67
                'custom-element' => 'amp-iframe',
68
            ],
69
            'webperf-amp-iframe-script'
70
        );
71
    }
72
73
    /*
74
     * @return void
75
     */
76
    public function includeAmpHtmlBeacon()
0 ignored issues
show
Coding Style introduced by
You must use "/**" style comments for a function comment
Loading history...
77
    {
78
        $html = PluginTemplate::renderPluginTemplate(
79
            '_frontend/scripts/load-boomerang-amp-iframe.twig',
80
            [
81
                'boomerangIframeUrl' => UrlHelper::siteUrl('/webperf/render/amp-iframe'),
82
            ]
83
        );
84
        echo $html;
85
    }
86
87
    /*
88
     * @return void
89
     */
90
    public function ampHtmlIframe()
0 ignored issues
show
Coding Style introduced by
You must use "/**" style comments for a function comment
Loading history...
91
    {
92
        $boomerangUrl = Craft::$app->assetManager->getPublishedUrl(
93
            '@nystudio107/webperf/assetbundles/boomerang/dist/js/boomerang-1.0.0.min.js',
94
            true
95
        );
96
        $html = PluginTemplate::renderPluginTemplate(
97
            '_frontend/scripts/boomerang-amp-iframe-html.twig',
98
            [
99
                'boomerangScriptUrl' => $boomerangUrl,
100
            ]
101
        );
102
103
        return $html;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $html returns the type string which is incompatible with the documented return type void.
Loading history...
104
    }
105
106
}
107