Passed
Push — develop ( 2d85f4...a6d9de )
by Andrew
06:09
created

Manifest::getFile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 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/
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\instantanalytics\helpers;
13
14
use nystudio107\instantanalytics\assetbundles\instantanalytics\InstantAnalyticsAsset;
15
use nystudio107\instantanalytics\helpers\Manifest as ManifestHelper;
16
17
use Craft;
18
use craft\helpers\Json as JsonHelper;
19
use craft\helpers\UrlHelper;
20
21
use yii\base\Exception;
22
use yii\caching\TagDependency;
23
use yii\web\NotFoundHttpException;
24
25
/**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
26
 * @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...
27
 * @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...
28
 * @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...
29
 */
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...
30
class Manifest
31
{
32
    // Constants
33
    // =========================================================================
34
35
    const ASSET_CLASS = InstantAnalyticsAsset::class;
36
37
    const CACHE_KEY = 'twigpack-' . self::ASSET_CLASS;
38
    const CACHE_TAG = 'twigpack-' . self::ASSET_CLASS;
39
40
    const DEVMODE_CACHE_DURATION = 1;
41
42
    const SUPPRESS_ERRORS_FOR_MODULES = [
43
        'styles.js',
44
        'commons.js',
45
        'vendors.js',
46
        'vendors.css',
47
        'styles.css',
48
    ];
49
50
    // Protected Static Properties
51
    // =========================================================================
52
53
    protected static $config = [
54
        // If `devMode` is on, use webpack-dev-server to all for HMR (hot module reloading)
55
        'useDevServer' => false,
56
        // Manifest names
57
        'manifest' => [
58
            'legacy' => 'manifest.json',
59
            'modern' => 'manifest.json',
60
        ],
61
        // Public server config
62
        'server' => [
63
            'manifestPath' => '/',
64
            'publicPath' => '/',
65
        ],
66
        // webpack-dev-server config
67
        'devServer' => [
68
            'manifestPath' => 'http://127.0.0.1:8080',
69
            'publicPath' => '/',
70
        ],
71
    ];
72
73
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
74
     * @var array
75
     */
76
    protected static $files;
77
78
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
79
     * @var bool
80
     */
81
    protected static $isHot = false;
82
83
    // Public Static Methods
84
    // =========================================================================
85
86
    /**
87
     * Simulate a static constructor
88
     *
89
     * ManifestVariable constructor.
90
     * @noinspection MagicMethodsValidityInspection
0 ignored issues
show
Coding Style introduced by
There must be exactly one blank line before the tags in a doc comment
Loading history...
91
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
92
    public static function __constructStatic()
0 ignored issues
show
Coding Style introduced by
Method name "Manifest::__constructStatic" is invalid; only PHP magic methods should be prefixed with a double underscore
Loading history...
Coding Style introduced by
Public method name "Manifest::__constructStatic" must not be prefixed with an underscore
Loading history...
93
    {
94
        ManifestHelper::invalidateCaches();
95
        $assetClass = self::ASSET_CLASS;
96
        $bundle = new $assetClass;
97
        $baseAssetsUrl = Craft::$app->assetManager->getPublishedUrl(
98
            $bundle->sourcePath,
99
            true
0 ignored issues
show
Unused Code introduced by
The call to yii\web\AssetManager::getPublishedUrl() has too many arguments starting with true. ( Ignorable by Annotation )

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

99
        /** @scrutinizer ignore-call */ 
100
        $baseAssetsUrl = Craft::$app->assetManager->getPublishedUrl(

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
100
        );
101
        self::$config['server']['manifestPath'] = Craft::getAlias($bundle->sourcePath);
102
        self::$config['server']['publicPath'] = $baseAssetsUrl;
103
        $useDevServer = getenv('NYS_PLUGIN_DEVSERVER');
104
        if ($useDevServer !== false) {
105
            self::$config['useDevServer'] = (bool)$useDevServer;
106
        }
107
    }
108
109
    /**
110
     * Get the passed in JS modules from the manifest, and register them in the current Craft view
111
     *
112
     * @param array $modules
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
113
     * @throws NotFoundHttpException
0 ignored issues
show
Coding Style introduced by
Tag @throws cannot be grouped with parameter tags in a doc comment
Loading history...
114
     * @throws \yii\base\InvalidConfigException
0 ignored issues
show
Coding Style introduced by
Tag @throws cannot be grouped with parameter tags in a doc comment
Loading history...
115
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
116
    public static function registerJsModules(array $modules)
117
    {
118
        $view = Craft::$app->getView();
119
        foreach($modules as $module) {
0 ignored issues
show
Coding Style introduced by
Expected "foreach (...) {\n"; found "foreach(...) {\n"
Loading history...
120
            $jsModule = self::getModule(self::$config, $module, 'modern');
121
            if ($jsModule) {
122
                $view->registerJsFile($jsModule, [
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
123
                    'depends' => self::ASSET_CLASS
124
                ]);
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
125
            }
126
        }
127
    }
128
129
    /**
130
     * Get the passed in CS modules from the manifest, and register them in the current Craft view
131
     *
132
     * @param array $modules
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
133
     * @throws NotFoundHttpException
0 ignored issues
show
Coding Style introduced by
Tag @throws cannot be grouped with parameter tags in a doc comment
Loading history...
134
     * @throws \yii\base\InvalidConfigException
0 ignored issues
show
Coding Style introduced by
Tag @throws cannot be grouped with parameter tags in a doc comment
Loading history...
135
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
136
    public static function registerCssModules(array $modules)
137
    {
138
        $view = Craft::$app->getView();
139
        foreach($modules as $module) {
0 ignored issues
show
Coding Style introduced by
Expected "foreach (...) {\n"; found "foreach(...) {\n"
Loading history...
140
            $cssModule = self::getModule(self::$config, $module, 'legacy');
141
            if ($cssModule) {
142
                $view->registerCssFile($cssModule, [
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
143
                    'depends' => self::ASSET_CLASS
144
                ]);
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
145
            }
146
        }
147
    }
148
149
    // Protected Static Methods
150
    // =========================================================================
151
152
    /**
153
     * Return the URI to a module
154
     *
155
     * @param array  $config
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
156
     * @param string $moduleName
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
157
     * @param string $type
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
158
     * @param bool   $soft
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
159
     *
160
     * @return null|string
161
     * @throws NotFoundHttpException
162
     */
163
    protected static function getModule(array $config, string $moduleName, string $type = 'modern', bool $soft = false)
164
    {
165
        // Get the module entry
166
        $module = self::getModuleEntry($config, $moduleName, $type, $soft);
167
        if ($module !== null) {
168
            $prefix = self::$isHot
169
                ? $config['devServer']['publicPath']
170
                : $config['server']['publicPath'];
171
            // If the module isn't a full URL, prefix it
172
            if (!UrlHelper::isAbsoluteUrl($module)) {
173
                $module = self::combinePaths($prefix, $module);
174
            }
175
            // Resolve any aliases
176
            $alias = Craft::getAlias($module, false);
177
            if ($alias) {
178
                $module = $alias;
179
            }
180
            // Make sure it's a full URL
181
            if (!UrlHelper::isAbsoluteUrl($module) && !is_file($module)) {
0 ignored issues
show
Bug introduced by
It seems like $module can also be of type true; however, parameter $filename of is_file() 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

181
            if (!UrlHelper::isAbsoluteUrl($module) && !is_file(/** @scrutinizer ignore-type */ $module)) {
Loading history...
Bug introduced by
It seems like $module can also be of type true; however, parameter $url of craft\helpers\UrlHelper::isAbsoluteUrl() 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

181
            if (!UrlHelper::isAbsoluteUrl(/** @scrutinizer ignore-type */ $module) && !is_file($module)) {
Loading history...
182
                try {
183
                    $module = UrlHelper::siteUrl($module);
0 ignored issues
show
Bug introduced by
It seems like $module can also be of type true; however, parameter $path of craft\helpers\UrlHelper::siteUrl() 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

183
                    $module = UrlHelper::siteUrl(/** @scrutinizer ignore-type */ $module);
Loading history...
184
                } catch (Exception $e) {
185
                    Craft::error($e->getMessage(), __METHOD__);
186
                }
187
            }
188
        }
189
190
        return $module;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $module also could return the type true which is incompatible with the documented return type null|string.
Loading history...
191
    }
192
193
    /**
194
     * Return a module's raw entry from the manifest
195
     *
196
     * @param array  $config
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
197
     * @param string $moduleName
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
198
     * @param string $type
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
199
     * @param bool   $soft
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
200
     *
201
     * @return null|string
202
     * @throws NotFoundHttpException
203
     */
204
    protected static function getModuleEntry(array $config, string $moduleName, string $type = 'modern', bool $soft = false)
205
    {
206
        $module = null;
207
        // Get the manifest file
208
        $manifest = self::getManifestFile($config, $type);
209
        if ($manifest !== null) {
210
            // Make sure it exists in the manifest
211
            if (empty($manifest[$moduleName])) {
212
                // Don't report errors for any files in SUPPRESS_ERRORS_FOR_MODULES
213
                if (!in_array($moduleName, self::SUPPRESS_ERRORS_FOR_MODULES)) {
214
                    self::reportError(Craft::t(
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
215
                        'instant-analytics',
216
                        'Module does not exist in the manifest: {moduleName}',
217
                        ['moduleName' => $moduleName]
218
                    ), $soft);
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
219
                }
220
221
                return null;
222
            }
223
            $module = $manifest[$moduleName];
224
        }
225
226
        return $module;
227
    }
228
229
    /**
230
     * Return a JSON-decoded manifest file
231
     *
232
     * @param array  $config
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
233
     * @param string $type
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
234
     *
235
     * @return null|array
236
     * @throws NotFoundHttpException
237
     */
238
    protected static function getManifestFile(array $config, string $type = 'modern')
239
    {
240
        $manifest = null;
241
        // Determine whether we should use the devServer for HMR or not
242
        $devMode = Craft::$app->getConfig()->getGeneral()->devMode;
243
        self::$isHot = ($devMode && $config['useDevServer']);
244
        // Try to get the manifest
245
        while ($manifest === null) {
246
            $manifestPath = self::$isHot
247
                ? $config['devServer']['manifestPath']
248
                : $config['server']['manifestPath'];
249
            // Normalize the path
250
            $path = self::combinePaths($manifestPath, $config['manifest'][$type]);
251
            $manifest = self::getJsonFile($path);
252
            // If the manifest isn't found, and it was hot, fall back on non-hot
253
            if ($manifest === null) {
254
                // We couldn't find a manifest; throw an error
255
                self::reportError(Craft::t(
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
256
                    'instant-analytics',
257
                    'Manifest file not found at: {manifestPath}',
258
                    ['manifestPath' => $manifestPath]
259
                ), true);
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
260
                if (self::$isHot) {
261
                    // Try again, but not with home module replacement
262
                    self::$isHot = false;
263
                } else {
264
                    // Give up and return null
265
                    return null;
266
                }
267
            }
268
        }
269
270
        return $manifest;
271
    }
272
273
    /**
274
     * Return the contents of a JSON file from a URI path
275
     *
276
     * @param string $path
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
277
     *
278
     * @return null|array
279
     */
280
    protected static function getJsonFile(string $path)
281
    {
282
        return self::getFileFromUri($path, [self::class, 'jsonFileDecode']);
283
    }
284
285
    /**
286
     * Invalidate all of the manifest caches
287
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
288
    public static function invalidateCaches()
289
    {
290
        $cache = Craft::$app->getCache();
291
        TagDependency::invalidate($cache, self::CACHE_TAG);
292
        Craft::info('All manifest caches cleared', __METHOD__);
293
    }
294
295
    /**
296
     * Return the contents of a file from a URI path
297
     *
298
     * @param string        $path
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
299
     * @param callable|null $callback
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
300
     *
301
     * @return null|mixed
302
     */
303
    protected static function getFileFromUri(string $path, callable $callback = null)
304
    {
305
        // Resolve any aliases
306
        $alias = Craft::getAlias($path, false);
307
        if ($alias) {
308
            $path = $alias;
309
        }
310
        // Make sure it's a full URL
311
        if (!UrlHelper::isAbsoluteUrl($path) && !is_file($path)) {
0 ignored issues
show
Bug introduced by
It seems like $path can also be of type true; however, parameter $filename of is_file() 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

311
        if (!UrlHelper::isAbsoluteUrl($path) && !is_file(/** @scrutinizer ignore-type */ $path)) {
Loading history...
Bug introduced by
It seems like $path can also be of type true; however, parameter $url of craft\helpers\UrlHelper::isAbsoluteUrl() 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

311
        if (!UrlHelper::isAbsoluteUrl(/** @scrutinizer ignore-type */ $path) && !is_file($path)) {
Loading history...
312
            try {
313
                $path = UrlHelper::siteUrl($path);
0 ignored issues
show
Bug introduced by
It seems like $path can also be of type true; however, parameter $path of craft\helpers\UrlHelper::siteUrl() 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

313
                $path = UrlHelper::siteUrl(/** @scrutinizer ignore-type */ $path);
Loading history...
314
            } catch (Exception $e) {
315
                Craft::error($e->getMessage(), __METHOD__);
316
            }
317
        }
318
319
        return self::getFileContents($path, $callback);
0 ignored issues
show
Bug introduced by
It seems like $path can also be of type true; however, parameter $path of nystudio107\instantanaly...fest::getFileContents() 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

319
        return self::getFileContents(/** @scrutinizer ignore-type */ $path, $callback);
Loading history...
320
    }
321
322
    /**
323
     * Return the contents of a file from the passed in path
324
     *
325
     * @param string   $path
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
326
     * @param callable $callback
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
327
     *
328
     * @return null|mixed
329
     */
330
    protected static function getFileContents(string $path, callable $callback = null)
331
    {
332
        // Return the memoized manifest if it exists
333
        if (!empty(self::$files[$path])) {
334
            return self::$files[$path];
335
        }
336
        // Create the dependency tags
337
        $dependency = new TagDependency([
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
338
            'tags' => [
339
                self::CACHE_TAG,
340
                self::CACHE_TAG.$path,
341
            ],
342
        ]);
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
343
        // Set the cache duration based on devMode
344
        $cacheDuration = Craft::$app->getConfig()->getGeneral()->devMode
345
            ? self::DEVMODE_CACHE_DURATION
346
            : null;
347
        // Get the result from the cache, or parse the file
348
        $cache = Craft::$app->getCache();
349
        $file = $cache->getOrSet(
350
            self::CACHE_KEY.$path,
351
            function () use ($path, $callback) {
352
                $result = null;
353
                $contents = @file_get_contents($path);
354
                if ($contents) {
355
                    $result = $contents;
356
                    if ($callback) {
357
                        $result = $callback($result);
358
                    }
359
                }
360
361
                return $result;
362
            },
363
            $cacheDuration,
364
            $dependency
365
        );
366
        self::$files[$path] = $file;
367
368
        return $file;
369
    }
370
371
    /**
372
     * Combined the passed in paths, whether file system or URL
373
     *
374
     * @param string ...$paths
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
375
     *
376
     * @return string
377
     */
378
    protected static function combinePaths(string ...$paths): string
379
    {
380
        $last_key = \count($paths) - 1;
381
        array_walk($paths, function (&$val, $key) use ($last_key) {
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
382
            switch ($key) {
383
                case 0:
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 12 spaces, found 16
Loading history...
384
                    $val = rtrim($val, '/ ');
385
                    break;
386
                case $last_key:
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 12 spaces, found 16
Loading history...
387
                    $val = ltrim($val, '/ ');
388
                    break;
389
                default:
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 12 spaces, found 16
Loading history...
390
                    $val = trim($val, '/ ');
391
                    break;
392
            }
393
        });
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
394
395
        $first = array_shift($paths);
396
        $last = array_pop($paths);
397
        $paths = array_filter($paths);
398
        array_unshift($paths, $first);
399
        $paths[] = $last;
400
401
        return implode('/', $paths);
402
    }
403
404
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
405
     * @param string $error
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
406
     * @param bool   $soft
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
407
     *
408
     * @throws NotFoundHttpException
409
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
410
    protected static function reportError(string $error, $soft = false)
411
    {
412
        $devMode = Craft::$app->getConfig()->getGeneral()->devMode;
413
        if ($devMode && !$soft) {
414
            throw new NotFoundHttpException($error);
415
        }
416
        Craft::error($error, __METHOD__);
417
    }
418
419
    // Private Static Methods
420
    // =========================================================================
421
422
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
423
     * @param $string
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
424
     *
425
     * @return mixed
426
     */
427
    private static function jsonFileDecode($string)
0 ignored issues
show
Coding Style introduced by
Private method name "Manifest::jsonFileDecode" must be prefixed with an underscore
Loading history...
428
    {
429
        return JsonHelper::decodeIfJson($string);
430
    }
431
}
432
433
// Simulate a static constructor
434
Manifest::__constructStatic();
435