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

TranslationsResource::uninstall()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 6
ccs 3
cts 3
cp 1
crap 2
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 TranslationsResource 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 translations files';
20 15
        $this->source = CommandHelper::getPackagePath('resources/lang');
21 15
        $this->target = resource_path('lang/vendor/adminlte');
22 15
        $this->required = true;
23
24
        // Fill the set of installation messages.
25
26 15
        $this->messages = [
27
            'install'   => 'Install the package translations files?',
28
            'overwrite' => 'The translation files already exists. Want to replace the files?',
29
            'success'   => 'Translation files 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 translations files.
41
42 10
        CommandHelper::copyDirectory($this->source, $this->target, true, true);
43 10
    }
44
45
    /**
46
     * Uninstall/Remove the resource.
47
     *
48
     * @return void
49
     */
50 10
    public function uninstall()
51
    {
52
        // Uninstall the translation files.
53
54 10
        if (is_dir($this->target)) {
55 10
            CommandHelper::removeDirectory($this->target);
56
        }
57 10
    }
58
59
    /**
60
     * Check if the resource already exists on the target destination.
61
     *
62
     * @return bool
63
     */
64 10
    public function exists()
65
    {
66 10
        return is_dir($this->target);
67
    }
68
69
    /**
70
     * Check if the resource is correctly installed.
71
     *
72
     * @return bool
73
     */
74 10
    public function installed()
75
    {
76 10
        return (bool) CommandHelper::compareDirectories(
77 10
            $this->source,
78 10
            $this->target,
79 10
            true
80
        );
81
    }
82
}
83