Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
50.00% covered (danger)
50.00%
6 / 12
40.00% covered (danger)
40.00%
4 / 10
CRAP
0.00% covered (danger)
0.00%
0 / 1
WorkKeysQuery
50.00% covered (danger)
50.00%
6 / 12
40.00% covered (danger)
40.00%
4 / 10
22.50
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 getId
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setId
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getIncludeSelf
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setIncludeSelf
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getWorkKeys
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setWorkKeys
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 containsTerm
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getAllTerms
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 replaceTerm
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3/**
4 * A work keys query.
5 *
6 * PHP version 8
7 *
8 * Copyright (C) The National Library of Finland 2023.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2,
12 * as published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22 *
23 * @category VuFind
24 * @package  Search
25 * @author   Ere Maijala <ere.maijala@helsinki.fi>
26 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
27 * @link     https://vufind.org
28 */
29
30namespace VuFindSearch\Query;
31
32/**
33 * A work keys query.
34 *
35 * @category VuFind
36 * @package  Search
37 * @author   Ere Maijala <ere.maijala@helsinki.fi>
38 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
39 * @link     https://vufind.org
40 */
41class WorkKeysQuery extends AbstractQuery
42{
43    /**
44     * Record ID
45     *
46     * @var ?string
47     */
48    protected $id;
49
50    /**
51     * Whether to include the record to compare with in the results
52     *
53     * @var bool
54     */
55    protected $includeSelf;
56
57    /**
58     * Work keys
59     *
60     * @var array
61     */
62    protected $workKeys;
63
64    /**
65     * Constructor.
66     *
67     * @param ?string $id          Record ID
68     * @param bool    $includeSelf Whether to include the record to compare with in the results
69     * @param array   $workKeys    Work keys to use
70     */
71    public function __construct(?string $id, bool $includeSelf, array $workKeys = [])
72    {
73        $this->id = $id;
74        $this->includeSelf = $includeSelf;
75        $this->workKeys = $workKeys;
76    }
77
78    /**
79     * Return record id
80     *
81     * @return ?string
82     */
83    public function getId(): ?string
84    {
85        return $this->id;
86    }
87
88    /**
89     * Set record id
90     *
91     * @param ?string $id Record id
92     *
93     * @return void
94     */
95    public function setId(?string $id)
96    {
97        $this->id = $id;
98    }
99
100    /**
101     * Return "include self" setting
102     *
103     * @return bool
104     */
105    public function getIncludeSelf(): bool
106    {
107        return $this->includeSelf;
108    }
109
110    /**
111     * Set "include self" setting
112     *
113     * @param bool $includeSelf New value
114     *
115     * @return void
116     */
117    public function setIncludeSelf(bool $includeSelf): void
118    {
119        $this->includeSelf = $includeSelf;
120    }
121
122    /**
123     * Return work keys
124     *
125     * @return array
126     */
127    public function getWorkKeys(): array
128    {
129        return $this->workKeys;
130    }
131
132    /**
133     * Set work keys
134     *
135     * @param array $workKeys Work keys
136     *
137     * @return void
138     */
139    public function setWorkKeys(array $workKeys): void
140    {
141        $this->workKeys = $workKeys;
142    }
143
144    /**
145     * Does the query contain the specified term? An optional normalizer can be
146     * provided to allow for fuzzier matching.
147     *
148     * @param string   $needle     Term to check
149     * @param callable $normalizer Function to normalize text strings (null for
150     * no normalization)
151     *
152     * @return bool
153     */
154    public function containsTerm($needle, $normalizer = null)
155    {
156        return false;
157    }
158
159    /**
160     * Get a concatenated list of all query strings within the object.
161     *
162     * @return string
163     */
164    public function getAllTerms()
165    {
166        return $this->id;
167    }
168
169    /**
170     * Replace a term.
171     *
172     * @param string   $from       Search term to find
173     * @param string   $to         Search term to insert
174     * @param callable $normalizer Function to normalize text strings (null for
175     * no normalization)
176     *
177     * @return void
178     */
179    public function replaceTerm($from, $to, $normalizer = null)
180    {
181        // Not applicable
182    }
183}