Completed
Pull Request — master (#6)
by Christopher
05:09
created

src/Console/Commands/Migration/Reindex.php (5 issues)

Labels
Severity
1
<?php
2
namespace Triadev\Es\Console\Commands\Migration;
3
4
use Triadev\Es\Contract\ElasticsearchIndexContract;
5
use Illuminate\Console\Command;
6
use Log;
7
8
class Reindex extends Command
9
{
10
    /**
11
     * The name and signature of the console command.
12
     *
13
     * @var string
14
     */
15
    protected $signature = 'triadev:es:reindex
16
                            {index : Index}
17
                            {from_version : From version}
18
                            {to_version : To version}';
19
20
    /**
21
     * The console command description.
22
     *
23
     * @var string
24
     */
25
    protected $description = 'Reindex the index.';
26
27
    /**
28
     * Execute the console command.
29
     *
30
     * @param ElasticsearchIndexContract $elasticsearchIndex
31
     */
32
    public function handle(ElasticsearchIndexContract $elasticsearchIndex)
33
    {
34
        $index = $this->argument('index');
35
        $from_version = $this->argument('from_version');
36
        $to_version = $this->argument('to_version');
37
38
        if (!$elasticsearchIndex->existIndex([$index], $from_version)) {
0 ignored issues
show
It seems like $from_version can also be of type string[]; however, parameter $version of Triadev\Es\Contract\Elas...xContract::existIndex() does only seem to accept null|string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

38
        if (!$elasticsearchIndex->existIndex([$index], /** @scrutinizer ignore-type */ $from_version)) {
Loading history...
39
            Log::error("The index (from) could not be found.", [
40
                'index' => $index,
41
                'from_version' => $from_version,
42
                'to_version' => $to_version
43
            ]);
44
        } elseif (!$elasticsearchIndex->existIndex([$index], $to_version)) {
45
            Log::error("The index (to) could not be found.", [
46
                'index' => $index,
47
                'from_version' => $from_version,
48
                'to_version' => $to_version
49
            ]);
50
        } else {
51
            try {
52
                $elasticsearchIndex->reindex($index, $from_version, $to_version);
0 ignored issues
show
It seems like $from_version can also be of type null and string[]; however, parameter $from_version of Triadev\Es\Contract\Elas...ndexContract::reindex() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

52
                $elasticsearchIndex->reindex($index, /** @scrutinizer ignore-type */ $from_version, $to_version);
Loading history...
It seems like $index can also be of type null and string[]; however, parameter $index of Triadev\Es\Contract\Elas...ndexContract::reindex() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

52
                $elasticsearchIndex->reindex(/** @scrutinizer ignore-type */ $index, $from_version, $to_version);
Loading history...
It seems like $to_version can also be of type null and string[]; however, parameter $to_version of Triadev\Es\Contract\Elas...ndexContract::reindex() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

52
                $elasticsearchIndex->reindex($index, $from_version, /** @scrutinizer ignore-type */ $to_version);
Loading history...
53
            } catch (\Exception $e) {
54
                Log::error(sprintf(
55
                    "The indices could not be reindex: %s",
56
                    $e->getMessage()
57
                ), $index);
0 ignored issues
show
It seems like $index can also be of type string; however, parameter $context of Illuminate\Support\Facades\Log::error() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

57
                ), /** @scrutinizer ignore-type */ $index);
Loading history...
58
            }
59
        }
60
    }
61
}
62