Passed
Push — master ( 70acef...8b9af3 )
by Florian
07:10 queued 02:43
created

ConfigResource   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 70
ccs 19
cts 19
cp 1
rs 10
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A exists() 0 3 1
A install() 0 6 1
A installed() 0 3 1
A __construct() 0 15 1
A uninstall() 0 6 2
1
<?php
2
3
namespace JeroenNoten\LaravelAdminLte\Console\PackageResources;
4
5
use JeroenNoten\LaravelAdminLte\Helpers\CommandHelper;
6
7
class ConfigResource extends PackageResource
8
{
9
    /**
10
     * Create a new resource instance.
11
     *
12
     * @return void
13
     */
14 18
    public function __construct()
15
    {
16
        // Fill the resource data.
17
18 18
        $this->description = 'The default package configuration file';
19 18
        $this->source = CommandHelper::getPackagePath('config/adminlte.php');
20 18
        $this->target = config_path('adminlte.php');
21 18
        $this->required = true;
22
23
        // Fill the set of installation messages.
24
25 18
        $this->messages = [
26
            'install'   => 'Install the package config file?',
27
            'overwrite' => 'The config file already exists. Want to replace it?',
28
            'success'   => 'Configuration file installed successfully.',
29
        ];
30 18
    }
31
32
    /**
33
     * Install/Export the resource.
34
     *
35
     * @return void
36
     */
37 8
    public function install()
38
    {
39
        // Install the configuration file.
40
41 8
        CommandHelper::ensureDirectoryExists(dirname($this->target));
42 8
        copy($this->source, $this->target);
43 8
    }
44
45
    /**
46
     * Uninstall/Remove the resource.
47
     *
48
     * @return void
49
     */
50 8
    public function uninstall()
51
    {
52
        // Uninstall the configuration file.
53
54 8
        if (is_file($this->target)) {
55 8
            unlink($this->target);
56
        }
57 8
    }
58
59
    /**
60
     * Check if the resource already exists on the target destination.
61
     *
62
     * @return bool
63
     */
64 8
    public function exists()
65
    {
66 8
        return is_file($this->target);
67
    }
68
69
    /**
70
     * Check if the resource is correctly installed.
71
     *
72
     * @return bool
73
     */
74 8
    public function installed()
75
    {
76 8
        return CommandHelper::compareFiles($this->source, $this->target);
77
    }
78
}
79