Test Failed
Push — master ( 0e7c47...0e4454 )
by Pavel
11:22 queued 11s
created

LaravelBackupPanel::assetsAreCurrent()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 9
rs 10
1
<?php
2
3
namespace PavelMironchik\LaravelBackupPanel;
4
5
use Closure;
6
use Illuminate\Http\Request;
7
use Illuminate\Support\Facades\File;
8
use RuntimeException;
9
10
class LaravelBackupPanel
11
{
12
    /**
13
     * The callback that should be used to authenticate Laravel Backup Panel users.
14
     *
15
     * @var Closure
16
     */
17
    public static $authUsing;
18
19
    /**
20
     * Determine if the given request can access the Laravel Backup Panel dashboard.
21
     *
22
     * @param  Request  $request
23
     * @return bool
24
     */
25
    public static function check($request)
26
    {
27
        return (static::$authUsing ?: function () {
28
            return app()->environment('local');
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

28
            return app()->/** @scrutinizer ignore-call */ environment('local');
Loading history...
29
        })($request);
30
    }
31
32
    /**
33
     * Set the callback that should be used to authenticate Laravel Backup Panel users.
34
     *
35
     * @param  Closure  $callback
36
     * @return static
37
     */
38
    public static function auth(Closure $callback)
39
    {
40
        static::$authUsing = $callback;
41
42
        return new static;
43
    }
44
45
    /**
46
     * Get the default JavaScript variables for Laravel Backup Panel.
47
     *
48
     * @return array
49
     */
50
    public static function scriptVariables()
51
    {
52
        return array_merge(
53
            config('laravel_backup_panel'),
54
            [
55
                'assetsAreCurrent' => static::assetsAreCurrent()
56
            ]
57
        );
58
    }
59
60
    /**
61
     * Determine if Laravel Backup Panel's published assets are up-to-date.
62
     *
63
     * @return bool
64
     *
65
     * @throws RuntimeException
66
     */
67
    private static function assetsAreCurrent()
68
    {
69
        $publishedPath = public_path('vendor/laravel_backup_panel/mix-manifest.json');
70
71
        if (! File::exists($publishedPath)) {
72
            throw new RuntimeException('Laravel Backup Panel assets are not published. Please run: php artisan vendor:publish --tag=laravel-backup-panel-assets --force');
73
        }
74
75
        return File::get($publishedPath) === File::get(__DIR__.'/../public/vendor/laravel_backup_panel/mix-manifest.json');
76
    }
77
}
78