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

ConfigResource::installed()   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 ConfigResource 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 configuration file';
20 15
        $this->source = CommandHelper::getPackagePath('config/adminlte.php');
21 15
        $this->target = config_path('adminlte.php');
22 15
        $this->required = true;
23
24
        // Fill the set of installation messages.
25
26 15
        $this->messages = [
27
            'install'   => 'Install the package config file?',
28
            'overwrite' => 'The config file already exists. Want to replace it?',
29
            'success'   => 'Configuration file installed successfully.',
30
        ];
31 15
    }
32
33
    /**
34
     * Install/Export the resource.
35
     *
36
     * @return void
37
     */
38 10
    public function install()
39
    {
40
        // Install the configuration file.
41
42 10
        CommandHelper::ensureDirectoryExists(dirname($this->target));
43 10
        copy($this->source, $this->target);
44 10
    }
45
46
    /**
47
     * Uninstall/Remove the resource.
48
     *
49
     * @return void
50
     */
51 10
    public function uninstall()
52
    {
53
        // Uninstall the configuration file.
54
55 10
        if (is_file($this->target)) {
56 10
            unlink($this->target);
57
        }
58 10
    }
59
60
    /**
61
     * Check if the resource already exists on the target destination.
62
     *
63
     * @return bool
64
     */
65 10
    public function exists()
66
    {
67 10
        return is_file($this->target);
68
    }
69
70
    /**
71
     * Check if the resource is correctly installed.
72
     *
73
     * @return bool
74
     */
75 10
    public function installed()
76
    {
77 10
        return CommandHelper::compareFiles($this->source, $this->target);
78
    }
79
}
80