ConfigResource   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 72
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 72
ccs 20
cts 20
cp 1
rs 10
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A install() 0 6 1
A __construct() 0 15 1
A exists() 0 3 1
A installed() 0 3 1
A uninstall() 0 7 2
1
<?php
2
3
namespace JeroenNoten\LaravelAdminLte\Console\PackageResources;
4
5
use Illuminate\Support\Facades\File;
6
use JeroenNoten\LaravelAdminLte\Helpers\CommandHelper;
7
8
class ConfigResource extends PackageResource
9
{
10
    /**
11
     * Create a new package resource instance.
12
     *
13
     * @return void
14
     */
15 30
    public function __construct()
16
    {
17
        // Fill the resource data.
18
19 30
        $this->description = 'The package configuration file with default options';
20 30
        $this->source = CommandHelper::getPackagePath('config/adminlte.php');
21 30
        $this->target = config_path('adminlte.php');
22 30
        $this->required = true;
23
24
        // Fill the set of installation messages.
25
26 30
        $this->messages = [
27 30
            'install' => 'Do you want to publish the package config file?',
28 30
            'overwrite' => 'Config file was already published. Want to replace it?',
29 30
            'success' => 'Configuration file published successfully',
30 30
        ];
31
    }
32
33
    /**
34
     * Installs or publishes the resource.
35
     *
36
     * @return void
37
     */
38 15
    public function install()
39
    {
40
        // Copy the configuration file to the target file.
41
42 15
        File::ensureDirectoryExists(File::dirname($this->target));
43 15
        File::copy($this->source, $this->target);
44
    }
45
46
    /**
47
     * Uninstalls the resource.
48
     *
49
     * @return void
50
     */
51 15
    public function uninstall()
52
    {
53
        // Delete the published configuration file. When file does not exists,
54
        // we consider the config file as uninstalled.
55
56 15
        if (File::isFile($this->target)) {
57 15
            File::delete($this->target);
58
        }
59
    }
60
61
    /**
62
     * Checks whether the resource already exists in the target location.
63
     *
64
     * @return bool
65
     */
66 11
    public function exists()
67
    {
68 11
        return File::isFile($this->target);
69
    }
70
71
    /**
72
     * Checks whether the resource is correctly installed, i.e. if the source
73
     * items matches with the items available at the target location.
74
     *
75
     * @return bool
76
     */
77 15
    public function installed()
78
    {
79 15
        return CommandHelper::compareFiles($this->source, $this->target);
80
    }
81
}
82