Passed
Push — v1 ( 3bfaf6...d06392 )
by Andrew
10:02 queued 04:19
created

Manifest   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 141
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 141
rs 10
c 0
b 0
f 0
wmc 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A getCssModuleTags() 0 6 1
A getCssRelPreloadPolyfill() 0 3 1
A getSafariNomoduleFix() 0 3 1
A getJsModuleTags() 0 6 1
A getCriticalCssTags() 0 6 1
A getCssInlineTags() 0 3 1
A getModule() 0 6 1
A getFile() 0 3 1
A invalidateCaches() 0 3 1
A getFileFromManifest() 0 6 1
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/
9
 * @copyright Copyright (c) 2018 nystudio107
10
 */
11
12
namespace nystudio107\twigpack\services;
13
14
use nystudio107\twigpack\Twigpack;
15
use nystudio107\twigpack\helpers\Manifest as ManifestHelper;
16
17
use craft\base\Component;
18
19
/** @noinspection MissingPropertyAnnotationsInspection */
20
21
/**
22
 * @author    nystudio107
23
 * @package   Twigpack
24
 * @since     1.0.0
25
 */
26
class Manifest extends Component
27
{
28
    // Public Methods
29
    // =========================================================================
30
31
    /**
32
     * Return the HTML tags to include the CSS
33
     *
34
     * @param string     $moduleName
35
     * @param bool       $async
36
     * @param null|array $config
37
     *
38
     * @return string
39
     * @throws \yii\web\NotFoundHttpException
40
     */
41
    public function getCssModuleTags(string $moduleName, bool $async = false, $config = null): string
42
    {
43
        $settings = Twigpack::$plugin->getSettings();
44
        $config = $config ?? $settings->getAttributes();
45
46
        return ManifestHelper::getCssModuleTags($config, $moduleName, $async);
47
    }
48
49
    /**
50
     * Returns the CSS file in $path wrapped in <style></style> tags
51
     *
52
     * @param $path
53
     *
54
     * @return string
55
     */
56
    public function getCssInlineTags(string $path): string
57
    {
58
        return ManifestHelper::getCssInlineTags($path);
59
    }
60
61
    /**
62
     * @param array $config
63
     * @param null|string $name
64
     *
65
     * @return string
66
     */
67
    public function getCriticalCssTags($name = null, $config = null): string
68
    {
69
        $settings = Twigpack::$plugin->getSettings();
70
        $config = $config ?? $settings->getAttributes();
71
72
        return ManifestHelper::getCriticalCssTags($config, $name);
73
    }
74
75
    /**
76
     * Returns the uglified loadCSS rel=preload Polyfill as per:
77
     * https://github.com/filamentgroup/loadCSS#how-to-use-loadcss-recommended-example
78
     *
79
     * @return string
80
     */
81
    public function getCssRelPreloadPolyfill(): string
82
    {
83
        return ManifestHelper::getCssRelPreloadPolyfill();
84
    }
85
86
    /**
87
     * Return the HTML tags to include the JavaScript module
88
     *
89
     * @param string     $moduleName
90
     * @param bool       $async
91
     * @param null|array $config
92
     *
93
     * @return null|string
94
     * @throws \yii\web\NotFoundHttpException
95
     */
96
    public function getJsModuleTags(string $moduleName, bool $async = false, $config = null)
97
    {
98
        $settings = Twigpack::$plugin->getSettings();
99
        $config = $config ?? $settings->getAttributes();
100
101
        return ManifestHelper::getJsModuleTags($config, $moduleName, $async);
102
    }
103
104
    /**
105
     * Return the Safari 10.1 nomodule JavaScript fix
106
     *
107
     * @return string
108
     */
109
    public function getSafariNomoduleFix(): string
110
    {
111
        return ManifestHelper::getSafariNomoduleFix();
112
    }
113
114
    /**
115
     * Return the URI to a module
116
     *
117
     * @param string $moduleName
118
     * @param string $type
119
     * @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...
120
     *
121
     * @return null|string
122
     * @throws \yii\web\NotFoundHttpException
123
     */
124
    public function getModule(string $moduleName, string $type = 'modern', $config = null)
125
    {
126
        $settings = Twigpack::$plugin->getSettings();
127
        $config = $config ?? $settings->getAttributes();
128
129
        return ManifestHelper::getModule($config, $moduleName, $type);
130
    }
131
132
    /**
133
     * Returns the contents of a file from a URI path
134
     *
135
     * @param string $path
136
     *
137
     * @return string
138
     */
139
    public function getFile(string $path): string
140
    {
141
        return ManifestHelper::getFile($path);
142
    }
143
144
    /**
145
     * Returns the contents of a file from the $fileName in the manifest
146
     *
147
     * @param string $fileName
148
     * @param string $type
149
     * @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...
150
     *
151
     * @return string
152
     */
153
    public function getFileFromManifest(string $fileName, string $type = 'legacy',  $config = null): string
154
    {
155
        $settings = Twigpack::$plugin->getSettings();
156
        $config = $config ?? $settings->getAttributes();
157
158
        return ManifestHelper::getFileFromManifest($config, $fileName, $type);
159
    }
160
161
    /**
162
     * Invalidate the manifest cache
163
     */
164
    public function invalidateCaches()
165
    {
166
        ManifestHelper::invalidateCaches();
167
    }
168
}
169