IndexAllEmployees::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

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