Completed
Push — api/develop ( e4271f...4a9872 )
by Bertrand
11:08
created

IndexAllEmployees::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 16
ccs 9
cts 9
cp 1
rs 9.4285
cc 2
eloc 9
nc 2
nop 0
crap 2
1
<?php
2
3
/**
4
 * This file is part of the HRis Software package.
5
 *
6
 * HRis - Human Resource and Payroll System
7
 *
8
 * @link http://github.com/HB-Co/HRis
9
 */
10
namespace HRis\Console\Commands;
11
12
use Exception;
13
use HRis\Api\Eloquent\Employee;
14
use HRis\Api\ThirdParty\Elastic;
15
use Illuminate\Console\Command;
16
use Illuminate\Support\Facades\Log;
17
18
class IndexAllEmployees extends Command
19
{
20
    /**
21
     * The name and signature of the console command.
22
     *
23
     * @var string
24
     */
25
    protected $signature = 'elasticsearch:employees';
26
27
    /**
28
     * The console command description.
29
     *
30
     * @var string
31
     */
32
    protected $description = 'Index all employee document to elastic search client';
33
34
    /**
35
     * @var Elastic
36
     */
37
    protected $elastic;
38
39
    /**
40
     * @var Employee
41
     */
42
    protected $employee;
43
44
    /**
45
     * Create a new command instance.
46
     *
47
     * @param Elastic  $elastic
48
     * @param Employee $employee
49
     */
50 2
    public function __construct(Elastic $elastic, Employee $employee)
51
    {
52 2
        parent::__construct();
53
54 2
        $this->elastic = $elastic;
55 2
        $this->employee = $employee;
56 2
    }
57
58
    /**
59
     * Execute the console command.
60
     *
61
     * @return mixed
62
     */
63 2
    public function handle()
64
    {
65 2
        $count = 0;
66
67
        try {
68 2
            $count = $this->elastic->indexAllEmployees($this->employee);
69 2
        } catch (Exception $e) {
70 2
            $this->error($e->getMessage());
71
        }
72
73 2
        $message = $count.' objects are successfully re-indexed.';
74
75 2
        $this->comment(PHP_EOL.$message.PHP_EOL);
76
77 2
        Log::info($message);
78 2
    }
79
}
80