Passed
Push — develop ( f852b5...b8485d )
by Andrew
08:00
created

ManifestVariable::includeSafariNomoduleFix()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace nystudio107\imageoptimize\variables;
4
5
use nystudio107\imageoptimize\helpers\Manifest as ManifestHelper;
6
use nystudio107\imageoptimize\assetbundles\imageoptimize\ImageOptimizeAsset;
7
8
use Craft;
9
use craft\helpers\Template;
10
11
class ManifestVariable
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class ManifestVariable
Loading history...
12
{
13
    // Protected Static Properties
14
    // =========================================================================
15
16
    protected static $config = [
17
        // If `devMode` is on, use webpack-dev-server to all for HMR (hot module reloading)
18
        'useDevServer' => true,
19
        // Manifest names
20
        'manifest'     => [
21
            'legacy' => 'manifest-legacy.json',
22
            'modern' => 'manifest.json',
23
        ],
24
        // Public server config
25
        'server'       => [
26
            'manifestPath' => '/',
27
            'publicPath' => '/',
28
        ],
29
        // webpack-dev-server config
30
        'devServer'    => [
31
            'manifestPath' => 'http://127.0.0.1:8080',
32
            'publicPath' => '/',
33
        ],
34
    ];
35
36
    // Public Methods
37
    // =========================================================================
38
39
    /**
40
     * ManifestVariable constructor.
41
     */
42
    public function __construct()
43
    {
44
        ManifestHelper::invalidateCaches();
45
        $bundle = new ImageOptimizeAsset();
46
        self::$config['server']['manifestPath'] = Craft::getAlias($bundle->sourcePath);
47
    }
48
49
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
50
     * @param string     $moduleName
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
51
     * @param bool       $async
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
52
     * @param null|array $config
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
53
     *
54
     * @return null|\Twig_Markup
55
     * @throws \yii\web\NotFoundHttpException
56
     */
57
    public function includeCssModule(string $moduleName, bool $async = false, $config = null)
0 ignored issues
show
Unused Code introduced by
The parameter $config is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

57
    public function includeCssModule(string $moduleName, bool $async = false, /** @scrutinizer ignore-unused */ $config = null)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
58
    {
59
        return Template::raw(
60
            ManifestHelper::getCssModuleTags(self::$config, $moduleName, $async)
61
        );
62
    }
63
64
    /**
65
     * Returns the uglified loadCSS rel=preload Polyfill as per:
66
     * https://github.com/filamentgroup/loadCSS#how-to-use-loadcss-recommended-example
67
     *
68
     * @return string
69
     */
70
    public static function includeCssRelPreloadPolyfill(): string
71
    {
72
        return Template::raw(
73
            ManifestHelper::getCssRelPreloadPolyfill()
74
        );
75
    }
76
77
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
78
     * @param string     $moduleName
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
79
     * @param bool       $async
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
80
     * @param null|array $config
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
81
     *
82
     * @return null|\Twig_Markup
83
     * @throws \yii\web\NotFoundHttpException
84
     */
85
    public function includeJsModule(string $moduleName, bool $async = false, $config = null)
0 ignored issues
show
Unused Code introduced by
The parameter $config is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

85
    public function includeJsModule(string $moduleName, bool $async = false, /** @scrutinizer ignore-unused */ $config = null)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
86
    {
87
        return Template::raw(
88
            ManifestHelper::getJsModuleTags(self::$config, $moduleName, $async)
89
        );
90
    }
91
92
    /**
93
     * Return the URI to a module
94
     *
95
     * @param string $moduleName
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
96
     * @param string $type
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
97
     * @param null   $config
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $config is correct as it would always require null to be passed?
Loading history...
Coding Style introduced by
Missing parameter comment
Loading history...
98
     *
99
     * @return null|\Twig_Markup
100
     * @throws \yii\web\NotFoundHttpException
101
     */
102
    public function getModuleUri(string $moduleName, string $type = 'modern', $config = null)
0 ignored issues
show
Unused Code introduced by
The parameter $config is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

102
    public function getModuleUri(string $moduleName, string $type = 'modern', /** @scrutinizer ignore-unused */ $config = null)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
103
    {
104
        return Template::raw(
105
            ManifestHelper::getModule(self::$config, $moduleName, $type)
106
        );
107
    }
108
109
    /**
110
     * Include the Safari 10.1 nomodule fix JavaScript
111
     *
112
     * @return \Twig_Markup
113
     */
114
    public function includeSafariNomoduleFix()
115
    {
116
        return Template::raw(
117
            ManifestHelper::getSafariNomoduleFix()
118
        );
119
    }
120
}
121