Passed
Push — master ( 706b38...4fe946 )
by Jonathan
01:00
created

GenerateCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 0
cts 6
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 2
crap 2
1
<?php namespace Spekkionu\Assetcachebuster\Console;
2
3
4
use Illuminate\Console\Command;
5
use Illuminate\Contracts\Config\Repository as Config;
6
use Spekkionu\Assetcachebuster\HashReplacer\HashReplacerInterface;
7
8
/**
9
 * Generates a new asset cache hash
10
 */
11
class GenerateCommand extends Command
12
{
13
    /**
14
     * The console command name.
15
     *
16
     * @var string
17
     */
18
    protected $name = 'assetcachebuster:generate';
19
20
    /**
21
     * The console command description.
22
     *
23
     * @var string
24
     */
25
    protected $description = 'Generates a new asset hash';
26
    /**
27
     * @var HashReplacerInterface
28
     */
29
    private $hashReplacer;
30
    /**
31
     * @var Config
32
     */
33
    private $config;
34
35
36
    /**
37
     * Create a new key generator command.
38
     *
39
     * @param HashReplacerInterface $hashReplacer
40
     * @param Config $config
41
     */
42
    public function __construct(HashReplacerInterface $hashReplacer, Config $config)
43
    {
44
        parent::__construct();
45
46
        $this->hashReplacer = $hashReplacer;
47
        $this->config = $config;
48
    }
49
50
    /**
51
     * Execute the console command.
52
     *
53
     * @return void
54
     */
55
    public function handle()
56
    {
57
        $this->line('Generating new asset hash. Environment: <comment>' . $this->laravel->make('env') . '</comment>');
58
59
        $hash = $this->hashReplacer->replaceHash();
60
61
        $this->config->set('assetcachebuster.hash', $hash);
62
63
        $msg = "New hash {$hash} generated.";
64
        $this->info($msg);
65
    }
66
67
}
68