Completed
Pull Request — master (#64)
by Thibaud
03:11
created

SearchRepository::search()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 14
rs 9.4285
cc 2
eloc 7
nc 2
nop 1
1
<?php
2
3
namespace PhraseanetSDK\Search;
4
5
use PhraseanetSDK\Exception\RuntimeException;
6
use PhraseanetSDK\AbstractRepository;
7
8
class SearchRepository extends AbstractRepository
9
{
10
11
    /**
12
     * Search for records
13
     *
14
     * @param  array                       $parameters Query parameters
15
     * @return \PhraseanetSDK\Entity\Query object
16
     * @throws RuntimeException
17
     */
18
    public function search(array $parameters = array())
19
    {
20
        $parameters = array_merge($parameters, [
21
            'search_type' => SearchResult::TYPE_RECORD
22
        ]);
23
24
        $response = $this->query('POST', 'v2/search/', array(), $parameters);
25
26
        if ($response->isEmpty()) {
27
            throw new RuntimeException('Response content is empty');
28
        }
29
30
        return SearchResults::fromValue($this->em, $parameters['search_type'], $response->getResult());
31
    }
32
}
33