FlushVarnishCache::handle()   A
last analyzed

Complexity

Conditions 3
Paths 5

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 9.6
c 0
b 0
f 0
cc 3
nc 5
nop 0
1
<?php
2
3
namespace DeltaBlue\Varnish\Commands;
4
5
use DeltaBlue\Varnish\Varnish;
6
use Illuminate\Console\Command;
7
8
class FlushVarnishCache extends Command
9
{
10
    /**
11
     * The console command name.
12
     *
13
     * @var string
14
     */
15
    protected $signature = 'varnish:flush';
16
17
    /**
18
     * The console command description.
19
     *
20
     * @var string
21
     */
22
    protected $description = 'Flush the varnish cache.';
23
24
    /**
25
     * Execute the console command.
26
     *
27
     * @return mixed
28
     */
29
    public function handle()
30
    {
31
        $success_msg = 'The varnish cache has been flushed!';
32
        $error_msg = 'Failed to flush the varnish cache!';
33
34
        try {
35
            if ((new Varnish())->flush()) {
36
                $this->comment($success_msg);
37
38
                return true;
39
            } else {
40
                $this->error($error_msg);
41
            }
42
        } catch (\Exception $exception) {
43
            $this->error($error_msg);
44
            $this->error($exception->getMessage());
45
        }
46
47
        return false;
48
    }
49
}
50