Passed
Pull Request — 2.x (#729)
by Antonio Carlos
05:57
created

twillViewName()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
nc 2
nop 2
dl 0
loc 11
ccs 0
cts 0
cp 0
crap 6
rs 10
c 1
b 0
f 0
1
<?php
2
3
use Illuminate\Support\Facades\Cache;
4
5 1
if (!function_exists('revAsset')) {
6
    /**
7
     * @param string $file
8
     * @return string
9
     */
10
    function revAsset($file)
11
    {
12
        if (!app()->environment('local', 'development')) {
0 ignored issues
show
introduced by
The method environment() does not exist on Illuminate\Container\Container. Are you sure you never get this type here, but always one of the subclasses? ( Ignorable by Annotation )

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

12
        if (!app()->/** @scrutinizer ignore-call */ environment('local', 'development')) {
Loading history...
13
            try {
14
                $manifest = Cache::rememberForever('rev-manifest', function () {
15
                    return json_decode(file_get_contents(config('twill.frontend.rev_manifest_path')), true);
16
                });
17
18
                if (isset($manifest[$file])) {
19
                    return (rtrim(config('twill.frontend.dist_assets_path'), '/') . '/') . $manifest[$file];
20
                }
21
22
            } catch (\Exception $e) {
23
                return '/' . $file;
24
            }
25
        }
26
27
        return (rtrim(config('twill.frontend.dev_assets_path'), '/') . '/') . $file;
28
    }
29
}
30
31 1
if (!function_exists('twillAsset')) {
32
    /**
33
     * @param string $file
34
     * @return string
35
     */
36
    function twillAsset($file)
37
    {
38 52
        if (app()->environment('local', 'development') && config('twill.dev_mode', false)) {
39
            $devServerUrl = config('twill.dev_mode_url', 'http://localhost:8080');
40
41
            try {
42
                $manifest = json_decode(file_get_contents(
43
                    $devServerUrl
44
                    . '/'
45
                    . config('twill.manifest_file', 'twill-manifest.json')
46
                ), true);
47
48
            } catch (\Exception $e) {
49
                throw new \Exception('Twill dev assets manifest is missing. Make sure you are running the npm run serve command inside Twill.');
50
            }
51
52
            return $devServerUrl . ($manifest[$file] ?? ('/' . $file));
53
        }
54
55
        try {
56
            $manifest = Cache::rememberForever('twill-manifest', function () {
57 52
                return json_decode(file_get_contents(
58 52
                    public_path(config('twill.public_directory', 'twill'))
59 52
                    . '/'
60 52
                    . config('twill.manifest_file', 'twill-manifest.json')
61 52
                ), true);
62 52
            });
63
        } catch (\Exception $e) {
64
            throw new \Exception('Twill assets manifest is missing. Make sure you published/updated Twill assets using the "php artisan twill:update" command.');
65
        }
66
67 52
        if (isset($manifest[$file])) {
68 52
            return $manifest[$file];
69
        }
70
71
        return '/' . config('twill.public_directory', 'twill') . '/' . $file;
72
    }
73
}
74
75 1
if (!function_exists('icon')) {
76
    /**
77
     * ARIA roles memo: 'presentation' means merely decoration. Otherwise, use role="img".
78
     *
79
     * @param string $name
80
     * @param array $opts
81
     * @return string
82
     */
83
    function icon($name, $opts = [])
84
    {
85
        $title = isset($opts['title']) ? ' title="' . htmlentities($opts['title'], ENT_QUOTES, 'UTF-8') . '" ' : '';
86
        $role = isset($opts['role']) ? ' role="' . htmlentities($opts['role'], ENT_QUOTES, 'UTF-8') . '" ' : ' role="presentation" ';
87
        $css_class = isset($opts['css_class']) ? htmlentities($opts['css_class'], ENT_QUOTES, 'UTF-8') : '';
88
        $svg_link = config('twill.frontend.svg_sprites_use_hash_only') ? "#icon--$name" : revAsset(config('twill.frontend.svg_sprites_path')) . "#icon--$name";
89
        return "<svg class=\"icon--$name $css_class\" $title $role><use xlink:href=\"" . $svg_link . "\"></use></svg>";
90
    }
91
}
92
93
if (!function_exists('twillViewName')) {
94
    function twillViewName($module, $suffix)
95
    {
96
        $view = "'admin.'.$module.'.{$suffix}'";
97
98
        if (view()->exists($view)) {
99
            return $view;
100
        }
101
102
        $prefix = app('twill.capsules.manager')->getCapsuleViewPrefix($module);
0 ignored issues
show
Bug introduced by
The method getCapsuleViewPrefix() does not exist on Illuminate\Contracts\Foundation\Application. ( Ignorable by Annotation )

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

102
        $prefix = app('twill.capsules.manager')->/** @scrutinizer ignore-call */ getCapsuleViewPrefix($module);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
103
104
        return "{$prefix}.{$suffix}";
105
    }
106
}
107