SearchManager   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 4

Importance

Changes 0
Metric Value
wmc 12
lcom 2
cbo 4
dl 0
loc 82
rs 10
c 0
b 0
f 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A search() 0 8 1
A addDocument() 0 4 1
A addDocuments() 0 4 1
A updateDocument() 0 4 1
A removeDocument() 0 4 1
A createIndex() 0 4 1
A flushIndex() 0 4 1
A removeIndex() 0 4 1
A getType() 0 8 2
A getTypes() 0 4 1
1
<?php
2
/*
3
 * WellCommerce Open-Source E-Commerce Platform
4
 * 
5
 * This file is part of the WellCommerce package.
6
 *
7
 * (c) Adam Piotrowski <[email protected]>
8
 * 
9
 * For the full copyright and license information,
10
 * please view the LICENSE file that was distributed with this source code.
11
 */
12
13
namespace WellCommerce\Bundle\SearchBundle\Manager;
14
15
use Doctrine\Common\Collections\Collection;
16
use WellCommerce\Component\Search\Adapter\AdapterInterface;
17
use WellCommerce\Component\Search\Exception\TypeNotFoundException;
18
use WellCommerce\Component\Search\Model\DocumentInterface;
19
use WellCommerce\Component\Search\Model\TypeInterface;
20
use WellCommerce\Component\Search\Request\SearchRequestInterface;
21
use WellCommerce\Component\Search\Storage\SearchResultStorage;
22
23
/**
24
 * Class SearchManager
25
 *
26
 * @author  Adam Piotrowski <[email protected]>
27
 */
28
final class SearchManager implements SearchManagerInterface
29
{
30
    /**
31
     * @var Collection
32
     */
33
    private $types;
34
    
35
    /**
36
     * @var SearchResultStorage
37
     */
38
    private $storage;
39
    
40
    /**
41
     * @var AdapterInterface
42
     */
43
    private $adapter;
44
45
    public function __construct(Collection $types, SearchResultStorage $storage, AdapterInterface $adapter)
46
    {
47
        $this->types   = $types;
48
        $this->storage = $storage;
49
        $this->adapter = $adapter;
50
    }
51
    
52
    public function search(SearchRequestInterface $request): array
53
    {
54
        $result = $this->adapter->search($request);
55
        
56
        $this->storage->setResult($result);
57
        
58
        return $result;
59
    }
60
    
61
    public function addDocument(DocumentInterface $document)
62
    {
63
        return $this->adapter->addDocument($document);
64
    }
65
    
66
    public function addDocuments(Collection $documents, string $locale, string $type)
67
    {
68
        return $this->adapter->addDocuments($documents, $locale, $type);
69
    }
70
    
71
    public function updateDocument(DocumentInterface $document)
72
    {
73
        return $this->adapter->addDocument($document);
74
    }
75
    
76
    public function removeDocument(DocumentInterface $document)
77
    {
78
        return $this->adapter->addDocument($document);
79
    }
80
    
81
    public function createIndex(string $locale, string $type)
82
    {
83
        $this->adapter->createIndex($locale, $type);
84
    }
85
    
86
    public function flushIndex(string $locale, string $type)
87
    {
88
        $this->adapter->flushIndex($locale, $type);
89
    }
90
    
91
    public function removeIndex(string $locale, string $type)
92
    {
93
        $this->adapter->removeIndex($locale, $type);
94
    }
95
    
96
    public function getType(string $type): TypeInterface
97
    {
98
        if (false === $this->types->containsKey($type)) {
99
            throw new TypeNotFoundException($type, $this->types->getKeys());
100
        }
101
        
102
        return $this->types->get($type);
103
    }
104
    
105
    public function getTypes(): Collection
106
    {
107
        return $this->types;
108
    }
109
}
110