Completed
Push — master ( 7d2bbd...4dac23 )
by Ryan
12:44 queued 04:33
created

CheckEntryIndex   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 59
rs 10
wmc 10
lcom 1
cbo 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
D handle() 0 34 9
1
<?php namespace Anomaly\Streams\Platform\Search\Command;
2
3
use Anomaly\Streams\Platform\Application\Application;
4
use Anomaly\Streams\Platform\Stream\Contract\StreamInterface;
5
use Illuminate\Contracts\Config\Repository;
6
use Illuminate\Filesystem\Filesystem;
7
use Laravel\Scout\EngineManager;
8
9
class CheckEntryIndex
10
{
11
    /**
12
     * The stream instance.
13
     *
14
     * @var StreamInterface
15
     */
16
    protected $stream;
17
18
    /**
19
     * Create a new CheckCreateIndex instance.
20
     *
21
     * @param StreamInterface $stream [description]
22
     */
23
    public function __construct(StreamInterface $stream)
24
    {
25
        $this->stream = $stream;
26
    }
27
28
    /**
29
     * Handle the command.
30
     *
31
     * @param Application $application
32
     */
33
    public function handle(Application $application, Filesystem $files)
34
    {
35
        if (!class_exists('TeamTNT\TNTSearch\TNTSearch')) {
36
            return;
37
        }
38
39
        if (!class_exists($this->stream->getEntryModelName())) {
40
            return;
41
        }
42
43
        $model = $this->stream->getEntryModel();
44
45
        $index = $application->getStoragePath('search/' . $model->searchableAs() . '.index');
46
47
        if ($this->stream->isSearchable() && file_exists($index)) {
48
            return;
49
        }
50
51
        if (!$this->stream->isSearchable() && file_exists($index)) {
52
            $files->delete($index);
53
54
            return;
55
        }
56
57
        if (!$this->stream->isSearchable()) {
58
            return;
59
        }
60
61
        try {
62
            app(EngineManager::class)->engine('tntsearch')->initIndex($model);
63
        } catch (\Exception $e) {
64
            // Kewl.
65
        }
66
    }
67
}
68