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

SearchRepository   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A search() 0 14 2
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 or stories, returning only references to the matching entities.
13
     *
14
     * @param  mixed[] $parameters Query parameters
15
     * @return SearchResults object
16
     * @throws RuntimeException
17
     */
18
    public function search(array $parameters = array())
19
    {
20
        $parameters = array_merge([
21
            'search_type' => SearchResult::TYPE_RECORD
22
        ], $parameters);
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