Completed
Pull Request — master (#363)
by Elan
01:56 queued 44s
created

SearchOptions   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 2
dl 0
loc 31
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A configureOptions() 0 18 1
1
<?php
2
3
namespace XHGui\Options;
4
5
use Symfony\Component\OptionsResolver\OptionsResolver;
6
use XHGui\Searcher\SearcherInterface;
7
8
class SearchOptions extends OptionsConfigurator
9
{
10
    /**
11
     * Options for SearchInterface::getAll
12
     *
13
     *  - sort:       an array of search criteria (TODO meta.SERVER.REQUEST_TIME => -1 ????)
14
     *  - direction:  an string, either 'desc' or 'asc'
15
     *  - page:       an integer, the page to display (e.g. 3)
16
     *  - perPage:    an integer, how many profiles to display per page (e.g. 25)
17
     *  - conditions: an array of criteria to match
18
     *  - projection: an array or bool
19
     */
20
    protected function configureOptions(OptionsResolver $resolver)
21
    {
22
        $resolver->setDefaults([
23
            'sort' => null,
24
            'direction' => SearcherInterface::DEFAULT_DIRECTION,
25
            'page' => SearcherInterface::DEFAULT_PAGE,
26
            'perPage' => null,
27
            'conditions' => [],
28
            'projection' => null,
29
        ]);
30
        $resolver->setRequired(['sort', 'direction', 'page', 'perPage']);
31
        $resolver->setAllowedTypes('sort', 'string');
32
        $resolver->setAllowedTypes('page', 'int');
33
        $resolver->setAllowedTypes('projection', ['null', 'bool', 'array']);
34
        $resolver->setAllowedTypes('conditions', 'array');
35
        $resolver->setAllowedValues('direction', ['asc', 'desc']);
36
        $resolver->setAllowedValues('sort', ['time', 'wt', 'cpu', 'mu', 'pmu']);
37
    }
38
}
39