Completed
Push — master ( f3d591...31e394 )
by Ben
02:18
created

CacheTranslationsCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
lcom 1
cbo 3
dl 0
loc 41
ccs 0
cts 18
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A handle() 0 13 2
1
<?php
2
3
namespace Thinktomorrow\Squanto\Services;
4
5
use Exception;
6
use Illuminate\Console\Command;
7
use Symfony\Component\Console\Helper\Table;
8
use Symfony\Component\Console\Helper\TableSeparator;
9
10
class CacheTranslationsCommand extends Command
11
{
12
    private $cacher;
13
    private $locales = [];
14
15
    public function __construct(CachedTranslationFile $cacher)
16
    {
17
        parent::__construct();
18
19
        $this->cacher = $cacher;
20
        $this->locales = config('squanto.locales', []);
0 ignored issues
show
Documentation Bug introduced by
It seems like config('squanto.locales', array()) of type * is incompatible with the declared type array of property $locales.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
21
    }
22
23
    /**
24
     * The name and signature of the console command.
25
     *
26
     * @var string
27
     */
28
    protected $signature = 'squanto:cache';
29
30
    /**
31
     * The console command description.
32
     *
33
     * @var string
34
     */
35
    protected $description = 'Clear cache and rebuild it from the database translations';
36
37
    public function handle()
38
    {
39
        if (empty($this->locales)) {
40
            throw new Exception('No locales set for the cache rebuild. Make sure you set your locales in the squanto config file');
41
        }
42
43
        $this->info('Clear and rebuild squanto cache for locales ['.implode(',', $this->locales).'].');
44
45
        $this->cacher->delete()->write();
46
47
        $this->info('Translation cache refreshed.');
48
        $this->output->writeln('');
49
    }
50
}
51