Completed
Pull Request — devel (#145)
by Litera
05:12
created

helpers.php ➔ webpackManifest()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 2
nop 1
dl 0
loc 10
ccs 0
cts 5
cp 0
crap 12
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
if(!function_exists('dd')) {
4
	/**
5
	 * Dump the passed variables and end the script.
6
	 *
7
	 * @codeCoverageIgnore
8
	 *
9
	 * @param  mixed
10
	 * @return void
11
	 */
12
	function dd() {
13
		array_map(function ($x){
14
			(\Tracy\Debugger::dump($x));
15
		}, func_get_args());
16
17
		die(1);
0 ignored issues
show
Coding Style Compatibility introduced by
The function dd() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
18
	}
19
}
20
21
if(!function_exists('appVersion')) {
22
	/**
23
	 * Get application version from package.json
24
	 *
25
	 * @return string
26
	 */
27
	function appVersion() {
28 1
		$packagePath = realpath(__DIR__ . '/../package.json');
29 1
		$package = json_decode(file_get_contents($packagePath));
30
31 1
		return $package->version;
32
	}
33
}
34
35
if(!function_exists('webpackManifest')) {
36
    /**
37
     * Get object from manifest.json
38
     *
39
     * @return string
40
     */
41
    function webpackManifest(string $name = null) {
42
        $manifestPath = realpath(__DIR__ . '/../www/manifest.json');
43
        $manifest = json_decode(file_get_contents($manifestPath), true);
44
45
        if ($name && array_key_exists($name, $manifest)) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $name of type null|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
46
            $manifest = $manifest[$name];
47
        }
48
49
        return $manifest;
50
    }
51
}
52
53
if(!function_exists('mainCss')) {
54
    /**
55
     * Get main css file from manifest.json
56
     *
57
     * @return string
58
     */
59
    function mainCss() {
60
        return webpackManifest('main.css');
61
    }
62
}
63
64
if(!function_exists('mainJs')) {
65
    /**
66
     * Get main js file from manifest.json
67
     *
68
     * @return string
69
     */
70
    function mainJs() {
71
        return webpackManifest('main.js');
72
    }
73
}
74
75
if(!function_exists('vendorJs')) {
76
    /**
77
     * Get vendor js file from manifest.json
78
     *
79
     * @return string
80
     */
81
    function vendorJs() {
82
        return webpackManifest('vendor.js');
83
    }
84
}
85