Prepare::handle()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 25

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 25
ccs 8
cts 8
cp 1
rs 9.52
c 0
b 0
f 0
cc 1
nc 1
nop 3
crap 1
1
<?php
2
3
namespace Nikaia\TranslationSheet\Commands;
4
5
use Illuminate\Console\Command;
6
use Nikaia\TranslationSheet\SheetPusher;
7
use Nikaia\TranslationSheet\Sheet\TranslationsSheet;
8
use Nikaia\TranslationSheet\Spreadsheet;
9
use Nikaia\TranslationSheet\Translation\Writer;
10
use Nikaia\TranslationSheet\Util;
11
12
class Prepare extends Command
13
{
14
    protected $signature = 'translation_sheet:prepare';
15
16
    protected $description = 'Rewrite locales languages files by removing comments and sorting keys. This most likely reduce and simplify conflicts when pulling translations from spreadsheet.';
17 1
18
    public function handle(SheetPusher $pusher, Spreadsheet $spreadsheet, Writer $writer)
19 1
    {
20 1
        $spreadsheet->sheets()->each(function (TranslationsSheet $translationsSheet) use ($pusher, $spreadsheet, $writer) {
21 1
22 1
            $this->output->writeln("<comment>Scanning local languages files for sheet [{$translationsSheet->getTitle()}]</comment>");
23
24
            $pusher = $pusher->setTranslationsSheet($translationsSheet);
0 ignored issues
show
Bug introduced by
Consider using a different name than the imported variable $pusher, or did you forget to import by reference?

It seems like you are assigning to a variable which was imported through a use statement which was not imported by reference.

For clarity, we suggest to use a different name or import by reference depending on whether you would like to have the change visibile in outer-scope.

Change not visible in outer-scope

$x = 1;
$callable = function() use ($x) {
    $x = 2; // Not visible in outer scope. If you would like this, how
            // about using a different variable name than $x?
};

$callable();
var_dump($x); // integer(1)

Change visible in outer-scope

$x = 1;
$callable = function() use (&$x) {
    $x = 2;
};

$callable();
var_dump($x); // integer(2)
Loading history...
25 1
26 1
            $translations = Util::keyValues(
27
                $pusher->getScannedAndTransformedTranslations(),
28 1
                $spreadsheet->getCamelizedHeader()
29 1
            );
30
31
            $this->output->writeln('<comment>.... Rewriting</comment>');
32
            $writer
33
                ->setTranslationsSheet($translationsSheet)
34
                ->setTranslations($translations)
35
                ->withOutput($this->output)
36
                ->write();
37
38
            $translationsSheet->api()->reset();
39
        });
40
41
        $this->output->writeln('<info>Done.</info>');
42
    }
43
}
44