Passed
Pull Request — master (#679)
by Diego
06:03
created

MainViewsResource::exists()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace JeroenNoten\LaravelAdminLte\Console\PackageResources;
4
5
use JeroenNoten\LaravelAdminLte\Console\PackageResources\PackageResource;
6
use JeroenNoten\LaravelAdminLte\Helpers\CommandHelper;
7
8
class MainViewsResource extends PackageResource
9
{
10
    /**
11
     * Create a new resource instance.
12
     *
13
     * @return void
14
     */
15 15
    public function __construct()
16
    {
17
        // Fill the resource data.
18
19 15
        $this->description = 'The default package main views';
20 15
        $this->source = CommandHelper::getPackagePath('resources/views');
21 15
        $this->target = CommandHelper::getViewPath('vendor/adminlte');
22 15
        $this->required = false;
23
24
        // Fill the set of installation messages.
25
26 15
        $this->messages = [
27
            'install'   => 'Install the AdminLTE main views?',
28
            'overwrite' => 'The main views already exists. Want to replace the views?',
29
            'success'   => 'Main views installed successfully.',
30
        ];
31 15
    }
32
33
    /**
34
     * Install/Export the resource.
35
     *
36
     * @return void
37
     */
38 4
    public function install()
39
    {
40
        // Install the main views.
41
42 4
        CommandHelper::copyDirectory($this->source, $this->target, true, true);
43 4
    }
44
45
    /**
46
     * Uninstall/Remove the resource.
47
     *
48
     * @return void
49
     */
50 4
    public function uninstall()
51
    {
52
        // Uninstall the package main views.
53
54 4
        if (is_dir($this->target)) {
55 4
            CommandHelper::removeDirectory($this->target);
56
        }
57 4
    }
58
59
    /**
60
     * Check if the resource already exists on the target destination.
61
     *
62
     * @return bool
63
     */
64 5
    public function exists()
65
    {
66 5
        return is_dir($this->target);
67
    }
68
69
    /**
70
     * Check if the resource is correctly installed.
71
     *
72
     * @return bool
73
     */
74 5
    public function installed()
75
    {
76 5
        return (bool) CommandHelper::compareDirectories(
77 5
            $this->source,
78 5
            $this->target,
79 5
            true
80
        );
81
    }
82
}
83