ManifestVariable::includeFileFromManifest()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 4
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\variables;
13
14
use craft\helpers\Template;
15
use nystudio107\twigpack\Twigpack;
16
use Twig\Error\LoaderError;
17
use Twig\Markup;
18
use yii\web\NotFoundHttpException;
19
20
/**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
21
 * @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...
22
 * @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...
23
 * @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...
24
 */
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...
25
class ManifestVariable
26
{
27
    // Public Methods
28
    // =========================================================================
29
30
    /**
31
     * Returns the uglified loadCSS rel=preload Polyfill as per:
32
     * https://github.com/filamentgroup/loadCSS#how-to-use-loadcss-recommended-example
33
     *
34
     * @return Markup
35
     */
36
    public static function includeCssRelPreloadPolyfill(): Markup
37
    {
38
        return Template::raw(
39
            Twigpack::$plugin->manifest->getCssRelPreloadPolyfill()
40
        );
41
    }
42
43
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
44
     * @param string $moduleName
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
45
     * @param bool $async
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 3 spaces after parameter type; 1 found
Loading history...
46
     * @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...
47
     *
48
     * @return Markup
49
     * @throws NotFoundHttpException
50
     */
51
    public function includeCssModule(string $moduleName, bool $async = false, array $attributes = []): Markup
52
    {
53
        return Template::raw(
54
            Twigpack::$plugin->manifest->getCssModuleTags($moduleName, $async, null, $attributes)
55
        );
56
    }
57
58
    /**
59
     * Returns the CSS file in $path wrapped in <style></style> tags
60
     *
61
     * @param string $path
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
62
     * @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...
63
     *
64
     * @return Markup
65
     */
66
    public function includeInlineCssTags(string $path, array $attributes = []): Markup
67
    {
68
        return Template::raw(
69
            Twigpack::$plugin->manifest->getCssInlineTags($path, $attributes)
70
        );
71
    }
72
73
    /**
74
     * Returns the Critical CSS file for $template wrapped in <style></style>
75
     * tags
76
     *
77
     * @param null|string $name
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
78
     * @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...
79
     *
80
     * @return Markup
81
     * @throws LoaderError
82
     */
83
    public function includeCriticalCssTags(?string $name = null, array $attributes = []): Markup
84
    {
85
        return Template::raw(
86
            Twigpack::$plugin->manifest->getCriticalCssTags($name, null, $attributes)
87
        );
88
    }
89
90
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
91
     * @param string $moduleName
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
92
     * @param bool $async
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 3 spaces after parameter type; 1 found
Loading history...
93
     * @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...
94
     *
95
     * @return Markup
96
     * @throws NotFoundHttpException
97
     */
98
    public function includeJsModule(string $moduleName, bool $async = false, array $attributes = []): Markup
99
    {
100
        return Template::raw(
101
            Twigpack::$plugin->manifest->getJsModuleTags($moduleName, $async, null, $attributes)
102
        );
103
    }
104
105
    /**
106
     * Return the URI to a module
107
     *
108
     * @param string $moduleName
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
109
     * @param string $type
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
110
     * @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...
Coding Style introduced by
Expected 3 spaces after parameter type; 1 found
Loading history...
111
     *
112
     * @return Markup
113
     * @throws NotFoundHttpException
114
     */
115
    public function getModuleUri(string $moduleName, string $type = 'modern', $config = null): Markup
116
    {
117
        return Template::raw(
118
            Twigpack::$plugin->manifest->getModule($moduleName, $type, $config)
0 ignored issues
show
Bug introduced by
It seems like nystudio107\twigpack\Twi...leName, $type, $config) can also be of type null; however, parameter $value of craft\helpers\Template::raw() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

118
            /** @scrutinizer ignore-type */ Twigpack::$plugin->manifest->getModule($moduleName, $type, $config)
Loading history...
119
        );
120
    }
121
122
    /**
123
     * Return the HASH value from 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 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...
Coding Style introduced by
Expected 3 spaces after parameter type; 1 found
Loading history...
128
     *
129
     * @return Markup
130
     * @throws NotFoundHttpException
131
     */
132
    public function getModuleHash(string $moduleName, string $type = 'modern', $config = null): Markup
133
    {
134
        return Template::raw(
135
            Twigpack::$plugin->manifest->getModuleHash($moduleName, $type, $config)
136
        );
137
    }
138
139
    /**
140
     * Include the Safari 10.1 nomodule fix JavaScript
141
     *
142
     * @param array $attributes additional HTML key/value pair attributes to add to the resulting tag
143
     *
144
     * @return Markup
145
     */
146
    public function includeSafariNomoduleFix(array $attributes = []): Markup
147
    {
148
        return Template::raw(
149
            Twigpack::$plugin->manifest->getSafariNomoduleFix($attributes)
150
        );
151
    }
152
153
    /**
154
     * Returns the contents of a file from a URI path
155
     *
156
     * @param string $path
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
157
     *
158
     * @return Markup
159
     */
160
    public function includeFile(string $path): Markup
161
    {
162
        return Template::raw(
163
            Twigpack::$plugin->manifest->getFile($path)
164
        );
165
    }
166
167
    /**
168
     * Returns the contents of a file from the $fileName in the manifest
169
     *
170
     * @param string $fileName
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
171
     * @param string $type
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
172
     * @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...
Coding Style introduced by
Expected 3 spaces after parameter type; 1 found
Loading history...
173
     *
174
     * @return Markup
175
     */
176
    public function includeFileFromManifest(string $fileName, string $type = 'legacy', $config = null): Markup
177
    {
178
        return Template::raw(
179
            Twigpack::$plugin->manifest->getFileFromManifest($fileName, $type, $config)
180
        );
181
    }
182
}
183