helpers.php ➔ pwa_meta()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
use CodexShaper\PWA\Model\Setting;
4
5
if (!function_exists('pwa_asset')) {
6
    /**
7
     * Get asset from given path.
8
     *
9
     * @param string $path
10
     *
11
     * @return \Illuminate\Http\Response
12
     */
13
    function pwa_asset($path)
14
    {
15
        return route('pwa.asset', ['path' => $path]);
16
    }
17
}
18
19
if (!function_exists('pwa_settings')) {
20
    /**
21
     * Get current domain's PWA settings.
22
     *
23
     * @return string
24
     */
25
    function pwa_settings()
26
    {
27
        return Setting::where('domain', '=', request()->getHttpHost())->first();
28
    }
29
}
30
31
if (!function_exists('pwa_meta')) {
32
    /**
33
     * Generate PWA meta, link and script tags.
34
     *
35
     * @return string
36
     */
37
    function pwa_meta()
38
    {
39
        echo view('pwa::meta')->render();
0 ignored issues
show
Bug introduced by
The method render does only exist in Illuminate\View\View, but not in Illuminate\Contracts\View\Factory.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
40
    }
41
}
42
43
if (!function_exists('last_icon_src')) {
44
    /**
45
     * Get last icon from manifest set.
46
     *
47
     * @return string
48
     */
49
    function last_icon_src()
50
    {
51
        $icons = pwa_settings()->data['manifest']['icons'];
52
        $lastIcon = end($icons);
53
54
        return $lastIcon['path'];
55
    }
56
}
57