Installer::install()   A
last analyzed

Complexity

Conditions 3
Paths 1

Size

Total Lines 31
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 3.0839

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
c 1
b 0
f 0
dl 0
loc 31
ccs 15
cts 19
cp 0.7895
rs 9.6333
cc 3
nc 1
nop 0
crap 3.0839
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * This file is part of Laravel Zero.
7
 *
8
 * (c) Nuno Maduro <[email protected]>
9
 *
10
 *  For the full copyright and license information, please view the LICENSE
11
 *  file that was distributed with this source code.
12
 */
13
14
namespace LaravelZero\Framework\Components\ScheduleList;
15
16
use Illuminate\Support\Facades\File;
17
use Illuminate\Support\Str;
18
use LaravelZero\Framework\Components\AbstractInstaller;
19
20
/**
21
 * @internal
22
 */
23
final class Installer extends AbstractInstaller
24
{
25
    /**
26
     * {@inheritdoc}
27
     */
28
    protected $name = 'install:schedule-list';
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    protected $description = 'Schedule List: List all scheduled commands.';
34
35
    /**
36
     * The config file path.
37
     */
38
    private const CONFIG_FILE = __DIR__.DIRECTORY_SEPARATOR.'stubs'.DIRECTORY_SEPARATOR.'schedule-list.php';
39
40
    /**
41
     * {@inheritdoc}
42
     */
43 2
    public function install(): void
44
    {
45 2
        $this->require('hmazter/laravel-schedule-list "^2.1"');
46
47 2
        $this->task(
48 2
            'Creating default schedule list configuration',
49
            function () {
50 2
                if (! File::exists($this->app->configPath('schedule-list.php'))) {
51
                    return File::copy(
52
                        static::CONFIG_FILE,
53
                        $this->app->configPath('schedule-list.php')
54
                    );
55
                }
56
57 2
                return false;
58 2
            }
59
        );
60
61 2
        $this->task(
62 2
            'Setting application name in configuration',
63
            function () {
64 2
                if (! File::exists($this->app->configPath('schedule-list.php'))) {
65
                    return false;
66
                }
67
68 2
                $updatedConfig = File::get($this->app->configPath('schedule-list.php'));
69 2
                $updatedConfig = str_replace('%APPLICATION_NAME%', Str::slug(config('app.name')), $updatedConfig);
70
71 2
                return File::put(
72 2
                    $this->app->configPath('schedule-list.php'),
73 2
                    $updatedConfig
74
                );
75 2
            }
76
        );
77 2
    }
78
}
79