1 | <?php |
||
27 | class QueryStringContainer { |
||
28 | |||
29 | /** |
||
30 | * @var string |
||
31 | */ |
||
32 | protected $keywords; |
||
33 | |||
34 | /** |
||
35 | * @var string |
||
36 | */ |
||
37 | protected $keywordsRaw; |
||
38 | |||
39 | /** |
||
40 | * @var |
||
41 | */ |
||
42 | protected $queryString; |
||
43 | |||
44 | /** |
||
45 | * @var bool |
||
46 | */ |
||
47 | private $rawQueryString = false; |
||
48 | |||
49 | /** |
||
50 | * QueryStrings constructor. |
||
51 | * @param string $keywords |
||
52 | */ |
||
53 | public function __construct($keywords) |
||
57 | |||
58 | /** |
||
59 | * Builds the query string which is then used for Solr's q parameters |
||
60 | * |
||
61 | * @return string Solr query string |
||
62 | */ |
||
63 | public function getQueryString() |
||
71 | |||
72 | /** |
||
73 | * Sets the query string without any escaping. |
||
74 | * |
||
75 | * Be cautious with this function! |
||
76 | * TODO remove this method as it basically just sets the q parameter / keywords |
||
77 | * |
||
78 | * @param string $queryString The raw query string. |
||
79 | */ |
||
80 | public function setQueryString($queryString) |
||
84 | |||
85 | /** |
||
86 | * Creates the string that is later used as the q parameter in the solr query |
||
87 | * |
||
88 | * @return void |
||
89 | */ |
||
90 | protected function buildQueryString() |
||
95 | |||
96 | /** |
||
97 | * Sets whether a raw query sting should be used, that is, whether the query |
||
98 | * string should be escaped or not. |
||
99 | * |
||
100 | * @param bool $useRawQueryString TRUE to use raw queries (like Lucene Query Language) or FALSE for regular, escaped queries |
||
101 | */ |
||
102 | public function useRawQueryString($useRawQueryString) |
||
106 | |||
107 | /** |
||
108 | * Get the query keywords, keywords are escaped. |
||
109 | * |
||
110 | * @return string query keywords |
||
111 | */ |
||
112 | public function getKeywords() |
||
116 | |||
117 | /** |
||
118 | * Sets the query keywords, escapes them as needed for Solr/Lucene. |
||
119 | * |
||
120 | * @param string $keywords user search terms/keywords |
||
121 | */ |
||
122 | public function setKeywords($keywords) |
||
127 | |||
128 | /** |
||
129 | * Gets the cleaned keywords so that it can be used in templates f.e. |
||
130 | * |
||
131 | * @return string The cleaned keywords. |
||
132 | */ |
||
133 | public function getKeywordsCleaned() |
||
137 | |||
138 | /** |
||
139 | * Gets the raw, unescaped, unencoded keywords. |
||
140 | * |
||
141 | * USE WITH CAUTION! |
||
142 | * |
||
143 | * @return string raw keywords |
||
144 | */ |
||
145 | public function getKeywordsRaw() |
||
149 | |||
150 | /** |
||
151 | * returns a string representation of the query |
||
152 | * |
||
153 | * @return string the string representation of the query |
||
154 | */ |
||
155 | public function __toString() |
||
159 | } |
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.