Pull::handle()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 20

Duplication

Lines 20
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 20
loc 20
ccs 0
cts 2
cp 0
rs 9.6
c 0
b 0
f 0
cc 3
nc 3
nop 2
crap 12
1
<?php
2
3
namespace Nikaia\TranslationSheet\Commands;
4
5
use Illuminate\Console\Command;
6
use Nikaia\TranslationSheet\Sheet\TranslationsSheet;
7
use Nikaia\TranslationSheet\SheetPuller;
8
use Nikaia\TranslationSheet\Spreadsheet;
9
10 View Code Duplication
class Pull extends Command
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
11
{
12
    protected $signature = 'translation_sheet:pull';
13
14
    protected $description = 'Pull translations from spreadsheet and override local languages files';
15
16
    public function handle(SheetPuller $puller, Spreadsheet $spreadsheet)
17
    {
18
        try {
19
            $spreadsheet->sheets()->each(function (TranslationsSheet $translationsSheet) use ($puller) {
20
                $puller
21
                    ->setTranslationsSheet($translationsSheet)
22
                    ->withOutput($this->output)
23
                    ->pull();
24
25
                $translationsSheet->api()->reset();
26
            });
27
        } catch (\ErrorException $e) {
28
            if ($e->getMessage() === 'Trying to access array offset on value of type null') {
29
                $this->error('Something is wrong. Did you just add an extra sheet ? try to re-run translation_sheet:setup!');
30
                return;
31
            }
32
33
            throw $e;
34
        }
35
    }
36
37
38
}
39