Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
SearchCommand
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
1
 getArguments
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3/**
4 * Perform a search and return record collection command.
5 *
6 * PHP version 8
7 *
8 * Copyright (C) Villanova University 2010.
9 * Copyright (C) The National Library of Finland 2021.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2,
13 * as published by the Free Software Foundation.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
23 *
24 * @category VuFind
25 * @package  Search
26 * @author   David Maus <maus@hab.de>
27 * @author   Aleksi Peebles <aleksi.peebles@helsinki.fi>
28 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
29 * @link     https://vufind.org
30 */
31
32namespace VuFindSearch\Command;
33
34use VuFindSearch\Backend\BackendInterface;
35use VuFindSearch\Command\Feature\QueryOffsetLimitTrait;
36use VuFindSearch\ParamBag;
37use VuFindSearch\Query\QueryInterface;
38
39/**
40 * Perform a search and return record collection command.
41 *
42 * @category VuFind
43 * @package  Search
44 * @author   David Maus <maus@hab.de>
45 * @author   Aleksi Peebles <aleksi.peebles@helsinki.fi>
46 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
47 * @link     https://vufind.org
48 */
49class SearchCommand extends CallMethodCommand
50{
51    use QueryOffsetLimitTrait;
52
53    /**
54     * SearchCommand constructor.
55     *
56     * @param string         $backendId Search backend identifier
57     * @param QueryInterface $query     Search query
58     * @param int            $offset    Search offset
59     * @param int            $limit     Search limit
60     * @param ?ParamBag      $params    Search backend parameters
61     */
62    public function __construct(
63        string $backendId,
64        QueryInterface $query,
65        int $offset = 0,
66        int $limit = 20,
67        ?ParamBag $params = null
68    ) {
69        $this->query = $query;
70        $this->offset = $offset;
71        $this->limit = $limit;
72        parent::__construct(
73            $backendId,
74            BackendInterface::class,
75            'search',
76            $params
77        );
78    }
79
80    /**
81     * Return search backend interface method arguments.
82     *
83     * @return array
84     */
85    public function getArguments(): array
86    {
87        return [
88            $this->getQuery(),
89            $this->getOffset(),
90            $this->getLimit(),
91            $this->getSearchParameters(),
92        ];
93    }
94}