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

TranslationsResource   A

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 17
c 1
b 0
f 0
dl 0
loc 72
ccs 21
cts 21
cp 1
rs 10
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A installed() 0 6 1
A install() 0 5 1
A uninstall() 0 6 2
A __construct() 0 15 1
A exists() 0 3 1
1
<?php
2
3
namespace JeroenNoten\LaravelAdminLte\Console\PackageResources;
4
5
use JeroenNoten\LaravelAdminLte\Helpers\CommandHelper;
6
7
class TranslationsResource 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 translations files';
19 18
        $this->source = CommandHelper::getPackagePath('resources/lang');
20 18
        $this->target = resource_path('lang/vendor/adminlte');
21 18
        $this->required = true;
22
23
        // Fill the set of installation messages.
24
25 18
        $this->messages = [
26
            'install'   => 'Install the package translations files?',
27
            'overwrite' => 'The translation files already exists. Want to replace the files?',
28
            'success'   => 'Translation files 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 translations files.
40
41 8
        CommandHelper::copyDirectory($this->source, $this->target, true, true);
42 8
    }
43
44
    /**
45
     * Uninstall/Remove the resource.
46
     *
47
     * @return void
48
     */
49 8
    public function uninstall()
50
    {
51
        // Uninstall the translation files.
52
53 8
        if (is_dir($this->target)) {
54 8
            CommandHelper::removeDirectory($this->target);
55
        }
56 8
    }
57
58
    /**
59
     * Check if the resource already exists on the target destination.
60
     *
61
     * @return bool
62
     */
63 8
    public function exists()
64
    {
65 8
        return is_dir($this->target);
66
    }
67
68
    /**
69
     * Check if the resource is correctly installed.
70
     *
71
     * @return bool
72
     */
73 8
    public function installed()
74
    {
75 8
        return (bool) CommandHelper::compareDirectories(
76 8
            $this->source,
77 8
            $this->target,
78 8
            true
79
        );
80
    }
81
}
82