1 | <?php |
||
26 | class Searchable extends Component |
||
27 | { |
||
28 | /** |
||
29 | * Search data with boolean mode. |
||
30 | */ |
||
31 | const BOOLEAN_SEARCH = 'boolean'; |
||
32 | |||
33 | /** |
||
34 | * Search data with fuzzy mode. |
||
35 | */ |
||
36 | const FUZZY_SEARCH = 'fuzzy'; |
||
37 | |||
38 | /** |
||
39 | * @var string default search mode for [[search()]] if `$mode` param not set. |
||
40 | */ |
||
41 | public $defaultSearchMode = self::FUZZY_SEARCH; |
||
42 | |||
43 | /** |
||
44 | * @var string the TNTSearch class. |
||
45 | */ |
||
46 | public $tntSearchClass = TNTSearch::class; |
||
47 | |||
48 | /** |
||
49 | * @var bool default as you type search config. |
||
50 | */ |
||
51 | public $asYouType = false; |
||
52 | |||
53 | /** |
||
54 | * @var bool default fuzziness search config. |
||
55 | */ |
||
56 | public $fuzziness = false; |
||
57 | |||
58 | /** |
||
59 | * @var int default fuzzy prefix length config. |
||
60 | */ |
||
61 | public $fuzzyPrefixLength = 2; |
||
62 | |||
63 | /** |
||
64 | * @var int default fuzzy max expansions config. |
||
65 | */ |
||
66 | public $fuzzyMaxExpansions = 50; |
||
67 | |||
68 | /** |
||
69 | * @var int default fuzzy distance config. |
||
70 | */ |
||
71 | public $fuzzyDistance = 2; |
||
72 | |||
73 | /** |
||
74 | * @var string default storage path of index data. |
||
75 | */ |
||
76 | public $storagePath = '@runtime/vxm/searchable'; |
||
77 | |||
78 | /** |
||
79 | * @var Queue|null use for support make or delete index data via worker. |
||
80 | */ |
||
81 | public $queue; |
||
82 | |||
83 | /** |
||
84 | * @inheritDoc |
||
85 | * @throws \yii\base\InvalidConfigException |
||
86 | */ |
||
87 | 13 | public function init() |
|
97 | |||
98 | /** |
||
99 | * Search by model class via given query string. |
||
100 | * |
||
101 | * @param string $modelClass need to search. |
||
102 | * @param string $query apply to search. |
||
103 | * @param string $mode boolean or fuzzy search mode. |
||
104 | * @param array $config of [[\vxm\searchable\TNTSearch]]. |
||
105 | * @param int $limit of values search. |
||
106 | * @return array search results. |
||
107 | * @throws \TeamTNT\TNTSearch\Exceptions\IndexNotFoundException |
||
108 | * @throws \yii\base\InvalidConfigException |
||
109 | */ |
||
110 | 8 | public function search(string $modelClass, string $query, ?string $mode = null, array $config = [], int $limit = 100): array |
|
126 | |||
127 | /** |
||
128 | * Delete all instances of the model class from the search index. |
||
129 | * |
||
130 | * @param string $modelClass need to delete all instances. |
||
131 | * @param array $config of [[\vxm\searchable\TNTSearch]]. |
||
132 | * @throws \yii\base\InvalidConfigException |
||
133 | */ |
||
134 | 5 | public function deleteAllFromSearch(string $modelClass, array $config = []): void |
|
144 | |||
145 | /** |
||
146 | * Dispatch the job to make the given models unsearchable. |
||
147 | * |
||
148 | * @param \yii\db\ActiveRecord|\yii\db\ActiveRecord[]|static|static[] $models dispatch to queue. |
||
149 | * @param array $config of [[\vxm\searchable\TNTSearch]]. |
||
150 | * @throws \TeamTNT\TNTSearch\Exceptions\IndexNotFoundException |
||
151 | * @throws \yii\base\InvalidConfigException |
||
152 | */ |
||
153 | 3 | public function queueDeleteFromSearch($models, array $config = []): void |
|
171 | |||
172 | /** |
||
173 | * Dispatch the job to make the given models searchable. |
||
174 | * |
||
175 | * @param \yii\db\ActiveRecord|\yii\db\ActiveRecord[]|static|static[] $models dispatch to queue job. |
||
176 | * @param array $config of [[\vxm\searchable\TNTSearch]]. |
||
177 | * @throws \TeamTNT\TNTSearch\Exceptions\IndexNotFoundException |
||
178 | * @throws \yii\base\InvalidConfigException |
||
179 | */ |
||
180 | 10 | public function queueMakeSearchable($models, array $config = []): void |
|
198 | |||
199 | /** |
||
200 | * Update or insert models to search engine. |
||
201 | * |
||
202 | * @param \yii\db\ActiveRecord|\yii\db\ActiveRecord[]|static|static[] $models dispatch to queue. |
||
203 | * @param array $config of [[\vxm\searchable\TNTSearch]]. |
||
204 | * @throws \TeamTNT\TNTSearch\Exceptions\IndexNotFoundException |
||
205 | * @throws \yii\base\InvalidConfigException |
||
206 | */ |
||
207 | 10 | public function upsert($models, array $config = []): void |
|
228 | |||
229 | /** |
||
230 | * Delete models from search engine. |
||
231 | * |
||
232 | * @param \yii\db\ActiveRecord|\yii\db\ActiveRecord[]|static|static[] $models need to delete. |
||
233 | * @param array $config of [[\vxm\searchable\TNTSearch]]. |
||
234 | * @throws \TeamTNT\TNTSearch\Exceptions\IndexNotFoundException |
||
235 | * @throws \yii\base\InvalidConfigException |
||
236 | */ |
||
237 | 3 | public function delete($models, array $config = []): void |
|
253 | |||
254 | /** |
||
255 | * Init index data of model class. |
||
256 | * |
||
257 | * @param string $modelClass to init index data. |
||
258 | * @param array $config of [[\vxm\searchable\TNTSearch]]. |
||
259 | * @throws \yii\base\InvalidConfigException |
||
260 | */ |
||
261 | 12 | public function initIndex(string $modelClass, array $config = []): void |
|
272 | |||
273 | /** |
||
274 | * Create tnt search object. |
||
275 | * |
||
276 | * @param Connection|null $db use to get database info. |
||
277 | * @param array $config of [[\vxm\searchable\TNTSearch]]. |
||
278 | * @return object|TNTSearch |
||
279 | * @throws \yii\base\InvalidConfigException |
||
280 | */ |
||
281 | 12 | public function createTNTSearch(?Connection $db = null, array $config = []): TNTSearch |
|
298 | |||
299 | |||
300 | } |
||
301 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.