Passed
Push — v1 ( 887199...d7f64b )
by Andrew
17:42 queued 08:53
created

Manifest::getFileFromUri()   A

Complexity

Conditions 5
Paths 6

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 17
rs 9.6111
c 0
b 0
f 0
cc 5
nc 6
nop 2
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\webperf\helpers;
13
14
use Craft;
0 ignored issues
show
Bug introduced by
The type Craft was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
use craft\helpers\Json as JsonHelper;
0 ignored issues
show
Bug introduced by
The type craft\helpers\Json was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
use craft\helpers\UrlHelper;
0 ignored issues
show
Bug introduced by
The type craft\helpers\UrlHelper was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
18
use yii\base\Exception;
0 ignored issues
show
Bug introduced by
The type yii\base\Exception was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
19
use yii\caching\TagDependency;
0 ignored issues
show
Bug introduced by
The type yii\caching\TagDependency was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
20
use yii\web\NotFoundHttpException;
0 ignored issues
show
Bug introduced by
The type yii\web\NotFoundHttpException was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

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 indented incorrectly; expected 2 spaces but found 4
Loading history...
24
 * @package   Twigpack
0 ignored issues
show
Coding Style introduced by
Tag value 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 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
28
{
29
    // Constants
30
    // =========================================================================
31
32
    const CACHE_KEY = 'twigpack-webperf';
33
    const CACHE_TAG = 'twigpack-webperf';
34
35
    const DEVMODE_CACHE_DURATION = 1;
36
37
    // Protected Static Properties
38
    // =========================================================================
39
40
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
41
     * @var array
42
     */
43
    protected static $files;
44
45
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
46
     * @var bool
47
     */
48
    protected static $isHot = false;
49
50
    // Public Static Methods
51
    // =========================================================================
52
53
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
54
     * @param array  $config
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
55
     * @param string $moduleName
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
56
     * @param bool   $async
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
57
     *
58
     * @return string
59
     * @throws NotFoundHttpException
60
     */
61
    public static function getCssModuleTags(array $config, string $moduleName, bool $async): string
62
    {
63
        $legacyModule = self::getModule($config, $moduleName, 'legacy', true);
64
        if ($legacyModule === null) {
65
            return '';
66
        }
67
        $lines = [];
68
        if ($async) {
69
            $lines[] = "<link rel=\"preload\" href=\"{$legacyModule}\" as=\"style\" onload=\"this.onload=null;this.rel='stylesheet'\" />";
70
            $lines[] = "<noscript><link rel=\"stylesheet\" href=\"{$legacyModule}\"></noscript>";
71
        } else {
72
            $lines[] = "<link rel=\"stylesheet\" href=\"{$legacyModule}\" />";
73
        }
74
75
        return implode("\r\n", $lines);
76
    }
77
78
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
79
     * @param string $path
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
80
     *
81
     * @return string
82
     */
83
    public static function getCssInlineTags(string $path): string
84
    {
85
        $result = self::getFile($path);
86
        if ($result) {
87
            $result = "<style>\r\n".$result."</style>\r\n";
88
            return $result;
89
        }
90
91
        return '';
92
    }
93
94
    /**
95
     * Returns the uglified loadCSS rel=preload Polyfill as per:
96
     * https://github.com/filamentgroup/loadCSS#how-to-use-loadcss-recommended-example
97
     *
98
     * @return string
99
     */
100
    public static function getCssRelPreloadPolyfill(): string
101
    {
102
        return <<<EOT
103
<script>
104
/*! loadCSS. [c]2017 Filament Group, Inc. MIT License */
105
!function(t){"use strict";t.loadCSS||(t.loadCSS=function(){});var e=loadCSS.relpreload={};if(e.support=function(){var e;try{e=t.document.createElement("link").relList.supports("preload")}catch(t){e=!1}return function(){return e}}(),e.bindMediaToggle=function(t){var e=t.media||"all";function a(){t.media=e}t.addEventListener?t.addEventListener("load",a):t.attachEvent&&t.attachEvent("onload",a),setTimeout(function(){t.rel="stylesheet",t.media="only x"}),setTimeout(a,3e3)},e.poly=function(){if(!e.support())for(var a=t.document.getElementsByTagName("link"),n=0;n<a.length;n++){var o=a[n];"preload"!==o.rel||"style"!==o.getAttribute("as")||o.getAttribute("data-loadcss")||(o.setAttribute("data-loadcss",!0),e.bindMediaToggle(o))}},!e.support()){e.poly();var a=t.setInterval(e.poly,500);t.addEventListener?t.addEventListener("load",function(){e.poly(),t.clearInterval(a)}):t.attachEvent&&t.attachEvent("onload",function(){e.poly(),t.clearInterval(a)})}"undefined"!=typeof exports?exports.loadCSS=loadCSS:t.loadCSS=loadCSS}("undefined"!=typeof global?global:this);
106
</script>
107
EOT;
108
    }
109
110
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
111
     * @param array  $config
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
112
     * @param string $moduleName
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
113
     * @param bool   $async
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
114
     *
115
     * @return null|string
116
     * @throws NotFoundHttpException
117
     */
118
    public static function getJsModuleTags(array $config, string $moduleName, bool $async)
119
    {
120
        $legacyModule = self::getModule($config, $moduleName, 'legacy');
121
        if ($legacyModule === null) {
122
            return '';
123
        }
124
        if ($async) {
125
            $modernModule = self::getModule($config, $moduleName, 'modern');
126
            if ($modernModule === null) {
127
                return '';
128
            }
129
        }
130
        $lines = [];
131
        if ($async) {
132
            $lines[] = "<script type=\"module\" src=\"{$modernModule}\"></script>";
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $modernModule does not seem to be defined for all execution paths leading up to this point.
Loading history...
133
            $lines[] = "<script nomodule src=\"{$legacyModule}\"></script>";
134
        } else {
135
            $lines[] = "<script src=\"{$legacyModule}\"></script>";
136
        }
137
138
        return implode("\r\n", $lines);
139
    }
140
141
    /**
142
     * Safari 10.1 supports modules, but does not support the `nomodule`
143
     * attribute - it will load <script nomodule> anyway. This snippet solve
144
     * this problem, but only for script tags that load external code, e.g.:
145
     * <script nomodule src="nomodule.js"></script>
146
     *
147
     * Again: this will **not* # prevent inline script, e.g.:
148
     * <script nomodule>alert('no modules');</script>.
149
     *
150
     * This workaround is possible because Safari supports the non-standard
151
     * 'beforeload' event. This allows us to trap the module and nomodule load.
152
     *
153
     * Note also that `nomodule` is supported in later versions of Safari -
154
     * it's just 10.1 that omits this attribute.
155
     *
156
     * c.f.: https://gist.github.com/samthor/64b114e4a4f539915a95b91ffd340acc
157
     *
158
     * @return string
159
     */
160
    public static function getSafariNomoduleFix(): string
161
    {
162
        return <<<EOT
163
<script>
164
!function(){var e=document,t=e.createElement("script");if(!("noModule"in t)&&"onbeforeload"in t){var n=!1;e.addEventListener("beforeload",function(e){if(e.target===t)n=!0;else if(!e.target.hasAttribute("nomodule")||!n)return;e.preventDefault()},!0),t.type="module",t.src=".",e.head.appendChild(t),t.remove()}}();
165
</script>
166
EOT;
167
    }
168
169
    /**
170
     * Return the URI to a module
171
     *
172
     * @param array  $config
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
173
     * @param string $moduleName
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 bool   $soft
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
176
     *
177
     * @return null|string
178
     * @throws NotFoundHttpException
179
     */
180
    public static function getModule(array $config, string $moduleName, string $type = 'modern', bool $soft = false)
181
    {
182
        // Get the module entry
183
        $module = self::getModuleEntry($config, $moduleName, $type, $soft);
184
        if ($module !== null) {
185
            $prefix = self::$isHot
186
                ? $config['devServer']['publicPath']
187
                : $config['server']['publicPath'];
188
            // If the module isn't a full URL, prefix it
189
            if (!UrlHelper::isAbsoluteUrl($module)) {
190
                $module = self::combinePaths($prefix, $module);
191
            }
192
            // Resolve any aliases
193
            $alias = Craft::getAlias($module, false);
194
            if ($alias) {
195
                $module = $alias;
196
            }
197
            // Make sure it's a full URL
198
            if (!UrlHelper::isAbsoluteUrl($module) && !is_file($module)) {
199
                try {
200
                    $module = UrlHelper::siteUrl($module);
201
                } catch (Exception $e) {
202
                    Craft::error($e->getMessage(), __METHOD__);
203
                }
204
            }
205
        } else {
206
            $module = '';
207
        }
208
209
        return $module;
210
    }
211
212
    /**
213
     * Return a module's raw entry from the manifest
214
     *
215
     * @param array  $config
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
216
     * @param string $moduleName
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
217
     * @param string $type
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
218
     * @param bool   $soft
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
219
     *
220
     * @return null|string
221
     * @throws NotFoundHttpException
222
     */
223
    public static function getModuleEntry(array $config, string $moduleName, string $type = 'modern', bool $soft = false)
224
    {
225
        $module = null;
226
        // Get the manifest file
227
        $manifest = self::getManifestFile($config, $type);
228
        if ($manifest !== null) {
229
            // Make sure it exists in the manifest
230
            if (empty($manifest[$moduleName])) {
231
                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...
232
                    'webperf',
233
                    'Module does not exist in the manifest: {moduleName}',
234
                    ['moduleName' => $moduleName]
235
                ), $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...
236
237
                return null;
238
            }
239
            $module = $manifest[$moduleName];
240
        }
241
242
        return $module;
243
    }
244
245
    /**
246
     * Return a JSON-decoded manifest file
247
     *
248
     * @param array  $config
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
249
     * @param string $type
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
250
     *
251
     * @return null|array
252
     * @throws NotFoundHttpException
253
     */
254
    public static function getManifestFile(array $config, string $type = 'modern')
255
    {
256
        $manifest = null;
257
        // Determine whether we should use the devServer for HMR or not
258
        $devMode = Craft::$app->getConfig()->getGeneral()->devMode;
259
        self::$isHot = ($devMode && $config['useDevServer']);
260
        // Try to get the manifest
261
        while ($manifest === null) {
262
            $manifestPath = self::$isHot
263
                ? $config['devServer']['manifestPath']
264
                : $config['server']['manifestPath'];
265
            // Normalize the path
266
            $path = self::combinePaths($manifestPath, $config['manifest'][$type]);
267
            $manifest = self::getJsonFile($path);
268
            // If the manifest isn't found, and it was hot, fall back on non-hot
269
            if ($manifest === null) {
270
                // We couldn't find a manifest; throw an error
271
                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...
272
                    'webperf',
273
                    'Manifest file not found at: {manifestPath}',
274
                    ['manifestPath' => $manifestPath]
275
                ), 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...
276
                if (self::$isHot) {
277
                    // Try again, but not with home module replacement
278
                    self::$isHot = false;
279
                } else {
280
                    // Give up and return null
281
                    return null;
282
                }
283
            }
284
        }
285
286
        return $manifest;
287
    }
288
289
    /**
290
     * Returns the contents of a file from a URI path
291
     *
292
     * @param string $path
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
293
     *
294
     * @return string
295
     */
296
    public static function getFile(string $path): string
297
    {
298
        return self::getFileFromUri($path, null) ?? '';
299
    }
300
301
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
302
     * @param array  $config
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
303
     * @param string $fileName
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
304
     * @param string $type
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
305
     *
306
     * @return string
307
     */
308
    public static function getFileFromManifest(array $config, string $fileName, string $type = 'legacy'): string
309
    {
310
        try {
311
            $path = self::getModuleEntry($config, $fileName, $type, true);
312
        } catch (NotFoundHttpException $e) {
313
            Craft::error($e->getMessage(), __METHOD__);
314
        }
315
        if ($path !== null) {
316
            $path = self::combinePaths(
317
                $config['localFiles']['basePath'],
318
                $path
319
            );
320
321
            return self::getFileFromUri($path, null) ?? '';
322
        }
323
324
        return '';
325
    }
326
327
    /**
328
     * Return the contents of a JSON file from a URI path
329
     *
330
     * @param string $path
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
331
     *
332
     * @return null|array
333
     */
334
    protected static function getJsonFile(string $path)
335
    {
336
        return self::getFileFromUri($path, [self::class, 'jsonFileDecode']);
337
    }
338
339
    /**
340
     * Invalidate all of the manifest caches
341
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
342
    public static function invalidateCaches()
343
    {
344
        $cache = Craft::$app->getCache();
345
        TagDependency::invalidate($cache, self::CACHE_TAG);
346
        Craft::info('All manifest caches cleared', __METHOD__);
347
    }
348
349
    // Protected Static Methods
350
    // =========================================================================
351
352
    /**
353
     * Return the contents of a file from a URI path
354
     *
355
     * @param string        $path
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
356
     * @param callable|null $callback
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
357
     *
358
     * @return null|mixed
359
     */
360
    protected static function getFileFromUri(string $path, callable $callback = null)
361
    {
362
        // Resolve any aliases
363
        $alias = Craft::getAlias($path, false);
364
        if ($alias) {
365
            $path = $alias;
366
        }
367
        // Make sure it's a full URL
368
        if (!UrlHelper::isAbsoluteUrl($path) && !is_file($path)) {
369
            try {
370
                $path = UrlHelper::siteUrl($path);
371
            } catch (Exception $e) {
372
                Craft::error($e->getMessage(), __METHOD__);
373
            }
374
        }
375
376
        return self::getFileContents($path, $callback);
377
    }
378
379
    /**
380
     * Return the contents of a file from the passed in path
381
     *
382
     * @param string   $path
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
383
     * @param callable $callback
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
384
     *
385
     * @return null|mixed
386
     */
387
    protected static function getFileContents(string $path, callable $callback = null)
388
    {
389
        // Return the memoized manifest if it exists
390
        if (!empty(self::$files[$path])) {
391
            return self::$files[$path];
392
        }
393
        // Create the dependency tags
394
        $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...
395
            'tags' => [
396
                self::CACHE_TAG,
397
                self::CACHE_TAG.$path,
398
            ],
399
        ]);
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...
400
        // Set the cache duration based on devMode
401
        $cacheDuration = Craft::$app->getConfig()->getGeneral()->devMode
402
            ? self::DEVMODE_CACHE_DURATION
403
            : null;
404
        // Get the result from the cache, or parse the file
405
        $cache = Craft::$app->getCache();
406
        $file = $cache->getOrSet(
407
            self::CACHE_KEY.$path,
408
            function () use ($path, $callback) {
409
                $result = null;
410
                $contents = @file_get_contents($path);
411
                if ($contents) {
412
                    $result = $contents;
413
                    if ($callback) {
414
                        $result = $callback($result);
415
                    }
416
                }
417
418
                return $result;
419
            },
420
            $cacheDuration,
421
            $dependency
422
        );
423
        self::$files[$path] = $file;
424
425
        return $file;
426
    }
427
428
    /**
429
     * Combined the passed in paths, whether file system or URL
430
     *
431
     * @param string ...$paths
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
432
     *
433
     * @return string
434
     */
435
    protected static function combinePaths(string ...$paths): string
436
    {
437
        $last_key = \count($paths) - 1;
438
        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...
439
            switch ($key) {
440
                case 0:
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 12 spaces, found 16
Loading history...
441
                    $val = rtrim($val, '/ ');
442
                    break;
443
                case $last_key:
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 12 spaces, found 16
Loading history...
444
                    $val = ltrim($val, '/ ');
445
                    break;
446
                default:
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 12 spaces, found 16
Loading history...
447
                    $val = trim($val, '/ ');
448
                    break;
449
            }
450
        });
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...
451
452
        $first = array_shift($paths);
453
        $last = array_pop($paths);
454
        $paths = array_filter($paths);
455
        array_unshift($paths, $first);
456
        $paths[] = $last;
457
458
        return implode('/', $paths);
459
    }
460
461
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
462
     * @param string $error
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
463
     * @param bool   $soft
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
464
     *
465
     * @throws NotFoundHttpException
466
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
467
    protected static function reportError(string $error, $soft = false)
468
    {
469
        $devMode = Craft::$app->getConfig()->getGeneral()->devMode;
470
        if ($devMode && !$soft) {
471
            throw new NotFoundHttpException($error);
472
        }
473
        Craft::error($error, __METHOD__);
474
    }
475
476
    // Private Static Methods
477
    // =========================================================================
478
479
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
Parameter $string should have a doc-comment as per coding-style.
Loading history...
480
     * @param $string
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter name
Loading history...
481
     *
482
     * @return mixed
483
     */
484
    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...
485
    {
486
        return JsonHelper::decodeIfJson($string);
487
    }
488
}
489