Manifest::getModule()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 6
rs 10
1
<?php
2
/**
3
 * Twigpack plugin for Craft CMS 3.x
4
 *
5
 * Twigpack is the conduit between Twig and webpack, with manifest.json &
6
 * webpack-dev-server HMR support
7
 *
8
 * @link      https://nystudio107.com/
0 ignored issues
show
Coding Style introduced by
The tag in position 1 should be the @copyright tag
Loading history...
9
 * @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...
10
 */
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...
11
12
namespace nystudio107\twigpack\services;
13
14
use craft\base\Component;
15
use nystudio107\twigpack\helpers\Manifest as ManifestHelper;
16
use nystudio107\twigpack\Twigpack;
17
use Twig\Error\LoaderError;
18
use yii\web\NotFoundHttpException;
19
20
/** @noinspection MissingPropertyAnnotationsInspection */
0 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
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 for @author tag indented incorrectly; expected 2 spaces but found 4
Loading history...
24
 * @package   Twigpack
0 ignored issues
show
Coding Style introduced by
Tag value for @package tag 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 for @since tag 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 Manifest extends Component
28
{
29
    // Public Methods
30
    // =========================================================================
31
32
    /**
33
     * Return the HTML tags to include the CSS
34
     *
35
     * @param string $moduleName
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 5 spaces after parameter type; 1 found
Loading history...
36
     * @param bool $async
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 7 spaces after parameter type; 1 found
Loading history...
37
     * @param null|array $config
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
38
     * @param array $attributes additional HTML key/value pair attributes to add to the resulting tag
0 ignored issues
show
Coding Style introduced by
Expected 6 spaces after parameter type; 1 found
Loading history...
39
     *
40
     * @return string
41
     * @throws NotFoundHttpException
42
     */
43
    public function getCssModuleTags(string $moduleName, bool $async = false, $config = null, array $attributes = []): string
44
    {
45
        $settings = Twigpack::$plugin->getSettings();
0 ignored issues
show
Bug introduced by
The method getSettings() does not exist on null. ( Ignorable by Annotation )

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

45
        /** @scrutinizer ignore-call */ 
46
        $settings = Twigpack::$plugin->getSettings();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
46
        $config = $config ?? $settings->getAttributes();
47
48
        return ManifestHelper::getCssModuleTags($config, $moduleName, $async, $attributes);
49
    }
50
51
    /**
52
     * Returns the CSS file in $path wrapped in <style></style> tags
53
     *
54
     * @param string $path
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
55
     * @param array $attributes additional HTML key/value pair attributes to add to the resulting tag
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
56
     *
57
     * @return string
58
     */
59
    public function getCssInlineTags(string $path, array $attributes = []): string
60
    {
61
        return ManifestHelper::getCssInlineTags($path, $attributes);
62
    }
63
64
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
65
     * @param array $config
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 7 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Doc comment for parameter $config does not match actual variable name $name
Loading history...
66
     * @param null|string $name
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Doc comment for parameter $name does not match actual variable name $config
Loading history...
67
     * @param array $attributes additional HTML key/value pair attributes to add to the resulting tag
0 ignored issues
show
Coding Style introduced by
Expected 7 spaces after parameter type; 1 found
Loading history...
68
     *
69
     * @return string
70
     * @throws LoaderError
71
     */
72
    public function getCriticalCssTags(?string $name = null, ?array $config = null, array $attributes = []): string
73
    {
74
        $settings = Twigpack::$plugin->getSettings();
75
        $config = $config ?? $settings->getAttributes();
76
77
        return ManifestHelper::getCriticalCssTags($config, $name, $attributes);
78
    }
79
80
    /**
81
     * Returns the uglified loadCSS rel=preload Polyfill as per:
82
     * https://github.com/filamentgroup/loadCSS#how-to-use-loadcss-recommended-example
83
     *
84
     * @return string
85
     */
86
    public function getCssRelPreloadPolyfill(): string
87
    {
88
        return ManifestHelper::getCssRelPreloadPolyfill();
0 ignored issues
show
Deprecated Code introduced by
The function nystudio107\twigpack\hel...CssRelPreloadPolyfill() has been deprecated: in 1.2.0 ( Ignorable by Annotation )

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

88
        return /** @scrutinizer ignore-deprecated */ ManifestHelper::getCssRelPreloadPolyfill();

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
89
    }
90
91
    /**
92
     * Return the HTML tags to include the JavaScript module
93
     *
94
     * @param string $moduleName
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 5 spaces after parameter type; 1 found
Loading history...
95
     * @param bool $async
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 7 spaces after parameter type; 1 found
Loading history...
96
     * @param null|array $config
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
97
     * @param array $attributes additional HTML key/value pair attributes to add to the resulting tag
0 ignored issues
show
Coding Style introduced by
Expected 6 spaces after parameter type; 1 found
Loading history...
98
     *
99
     * @return null|string
100
     * @throws NotFoundHttpException
101
     */
102
    public function getJsModuleTags(string $moduleName, bool $async = false, ?array $config = null, array $attributes = [])
103
    {
104
        $settings = Twigpack::$plugin->getSettings();
105
        $config = $config ?? $settings->getAttributes();
106
107
        return ManifestHelper::getJsModuleTags($config, $moduleName, $async, $attributes);
108
    }
109
110
    /**
111
     * Return the Safari 10.1 nomodule JavaScript fix
112
     *
113
     * @param array $attributes additional HTML key/value pair attributes to add to the resulting tag
114
     *
115
     * @return string
116
     */
117
    public function getSafariNomoduleFix(array $attributes = []): string
118
    {
119
        return ManifestHelper::getSafariNomoduleFix($attributes);
120
    }
121
122
    /**
123
     * Return the URI to a module
124
     *
125
     * @param string $moduleName
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
126
     * @param string $type
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
127
     * @param ?array $config
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
128
     *
129
     * @return null|string
130
     * @throws NotFoundHttpException
131
     */
132
    public function getModule(string $moduleName, string $type = 'modern', $config = null): ?string
133
    {
134
        $settings = Twigpack::$plugin->getSettings();
135
        $config = $config ?? $settings->getAttributes();
136
137
        return ManifestHelper::getModule($config, $moduleName, $type);
138
    }
139
140
    /**
141
     * Return the HASH value from a module
142
     *
143
     * @param string $moduleName
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
144
     * @param string $type
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
145
     * @param ?array $config
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
146
     *
147
     * @return null|string
148
     * @throws NotFoundHttpException
149
     */
150
    public function getModuleHash(string $moduleName, string $type = 'modern', $config = null): ?string
151
    {
152
        $settings = Twigpack::$plugin->getSettings();
153
        $config = $config ?? $settings->getAttributes();
154
155
        return ManifestHelper::getModuleHash($config, $moduleName, $type);
156
    }
157
158
    /**
159
     * Returns the contents of a file from a URI path
160
     *
161
     * @param string $path
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
162
     *
163
     * @return string
164
     */
165
    public function getFile(string $path): string
166
    {
167
        return ManifestHelper::getFile($path);
168
    }
169
170
    /**
171
     * Returns the contents of a file from the $fileName in the manifest
172
     *
173
     * @param string $fileName
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
174
     * @param string $type
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
175
     * @param ?array $config
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
176
     *
177
     * @return string
178
     */
179
    public function getFileFromManifest(string $fileName, string $type = 'legacy', $config = null): string
180
    {
181
        $settings = Twigpack::$plugin->getSettings();
182
        $config = $config ?? $settings->getAttributes();
183
184
        return ManifestHelper::getFileFromManifest($config, $fileName, $type);
185
    }
186
187
    /**
188
     * Invalidate the manifest cache
189
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
190
    public function invalidateCaches()
191
    {
192
        ManifestHelper::invalidateCaches();
193
    }
194
}
195