Code Duplication    Length = 23-29 lines in 2 locations

src/Commands/Pull.php 1 location

@@ 10-38 (lines=29) @@
7
use Nikaia\TranslationSheet\SheetPuller;
8
use Nikaia\TranslationSheet\Spreadsheet;
9
10
class Pull extends Command
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

src/Commands/Push.php 1 location

@@ 11-33 (lines=23) @@
8
use Nikaia\TranslationSheet\Spreadsheet;
9
use Symfony\Component\Finder\Exception\DirectoryNotFoundException;
10
11
class Push extends Command
12
{
13
    protected $signature = 'translation_sheet:push';
14
15
    protected $description = 'Push translation from your local languages files to the spreadsheet';
16
17
    public function handle(SheetPusher $pusher, Spreadsheet $spreadsheet)
18
    {
19
        try {
20
            $spreadsheet->sheets()->each(function (TranslationsSheet $translationsSheet) use ($pusher) {
21
                $pusher
22
                    ->setTranslationsSheet($translationsSheet)
23
                    ->withOutput($this->output)
24
                    ->push();
25
                
26
                $translationsSheet->api()->reset();
27
            });
28
        } catch (DirectoryNotFoundException $e) {
29
            $this->error($e->getMessage());
30
            $this->error('Something is wrong. Did you just add an extra sheet ? try to re-run translation_sheet:setup!');
31
        }
32
    }
33
}
34