aboutsummaryrefslogtreecommitdiff
path: root/app/Models/Search.php
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2022-01-06 22:39:35 +0100
committerGravatar GitHub <noreply@github.com> 2022-01-06 22:39:35 +0100
commit8e398d24f132095fffba0db3c7ceea9a43371b4d (patch)
treeea40e91c9e55f590826dc6571f2a9a098431535c /app/Models/Search.php
parentd339b6dd454d814ffc323fa9077b70e33339c479 (diff)
Fix several PHP8.1 warnings (#4123)
* Fix several PHP8.1 warnings Taking advantage of https://github.com/FreshRSS/FreshRSS/pull/4121 * Couple oh type hints missing * Compatibility PHP 7 * Fix variadic PHPDocs syntax
Diffstat (limited to 'app/Models/Search.php')
-rw-r--r--app/Models/Search.php115
1 files changed, 36 insertions, 79 deletions
diff --git a/app/Models/Search.php b/app/Models/Search.php
index 08669f738..d5088191e 100644
--- a/app/Models/Search.php
+++ b/app/Models/Search.php
@@ -42,6 +42,9 @@ class FreshRSS_Search {
private $not_tags;
private $not_search;
+ /**
+ * @param string|null $input
+ */
public function __construct($input) {
if ($input == '') {
return;
@@ -77,7 +80,7 @@ class FreshRSS_Search {
$input = $this->parseTagsSearch($input);
$input = $this->parseNotSearch($input);
- $input = $this->parseSearch($input);
+ $this->parseSearch($input);
}
public function __toString() {
@@ -201,11 +204,8 @@ class FreshRSS_Search {
/**
* Parse the search string to find entry (article) IDs.
- *
- * @param string $input
- * @return string
*/
- private function parseEntryIds($input) {
+ private function parseEntryIds(string $input): string {
if (preg_match_all('/\be:(?P<search>[0-9,]*)/', $input, $matches)) {
$input = str_replace($matches[0], '', $input);
$ids_lists = $matches['search'];
@@ -221,7 +221,7 @@ class FreshRSS_Search {
return $input;
}
- private function parseNotEntryIds($input) {
+ private function parseNotEntryIds(string $input): string {
if (preg_match_all('/[!-]e:(?P<search>[0-9,]*)/', $input, $matches)) {
$input = str_replace($matches[0], '', $input);
$ids_lists = $matches['search'];
@@ -237,13 +237,7 @@ class FreshRSS_Search {
return $input;
}
- /**
- * Parse the search string to find feed IDs.
- *
- * @param string $input
- * @return string
- */
- private function parseFeedIds($input) {
+ private function parseFeedIds(string $input): string {
if (preg_match_all('/\bf:(?P<search>[0-9,]*)/', $input, $matches)) {
$input = str_replace($matches[0], '', $input);
$ids_lists = $matches['search'];
@@ -259,7 +253,7 @@ class FreshRSS_Search {
return $input;
}
- private function parseNotFeedIds($input) {
+ private function parseNotFeedIds(string $input): string {
if (preg_match_all('/[!-]f:(?P<search>[0-9,]*)/', $input, $matches)) {
$input = str_replace($matches[0], '', $input);
$ids_lists = $matches['search'];
@@ -277,11 +271,8 @@ class FreshRSS_Search {
/**
* Parse the search string to find tags (labels) IDs.
- *
- * @param string $input
- * @return string
*/
- private function parseLabelIds($input) {
+ private function parseLabelIds(string $input): string {
if (preg_match_all('/\b[lL]:(?P<search>[0-9,]+|[*])/', $input, $matches)) {
$input = str_replace($matches[0], '', $input);
$ids_lists = $matches['search'];
@@ -301,7 +292,7 @@ class FreshRSS_Search {
return $input;
}
- private function parseNotLabelIds($input) {
+ private function parseNotLabelIds(string $input): string {
if (preg_match_all('/[!-][lL]:(?P<search>[0-9,]+|[*])/', $input, $matches)) {
$input = str_replace($matches[0], '', $input);
$ids_lists = $matches['search'];
@@ -323,11 +314,8 @@ class FreshRSS_Search {
/**
* Parse the search string to find tags (labels) names.
- *
- * @param string $input
- * @return string
*/
- private function parseLabelNames($input) {
+ private function parseLabelNames(string $input): string {
$names_lists = [];
if (preg_match_all('/\blabels?:(?P<delim>[\'"])(?P<search>.*)(?P=delim)/U', $input, $matches)) {
$names_lists = $matches['search'];
@@ -352,11 +340,8 @@ class FreshRSS_Search {
/**
* Parse the search string to find tags (labels) names to exclude.
- *
- * @param string $input
- * @return string
*/
- private function parseNotLabelNames($input) {
+ private function parseNotLabelNames(string $input): string {
$names_lists = [];
if (preg_match_all('/[!-]labels?:(?P<delim>[\'"])(?P<search>.*)(?P=delim)/U', $input, $matches)) {
$names_lists = $matches['search'];
@@ -380,14 +365,10 @@ class FreshRSS_Search {
}
/**
- * Parse the search string to find intitle keyword and the search related
- * to it.
+ * Parse the search string to find intitle keyword and the search related to it.
* The search is the first word following the keyword.
- *
- * @param string $input
- * @return string
*/
- private function parseIntitleSearch($input) {
+ private function parseIntitleSearch(string $input): string {
if (preg_match_all('/\bintitle:(?P<delim>[\'"])(?P<search>.*)(?P=delim)/U', $input, $matches)) {
$this->intitle = $matches['search'];
$input = str_replace($matches[0], '', $input);
@@ -400,7 +381,7 @@ class FreshRSS_Search {
return $input;
}
- private function parseNotIntitleSearch($input) {
+ private function parseNotIntitleSearch(string $input): string {
if (preg_match_all('/[!-]intitle:(?P<delim>[\'"])(?P<search>.*)(?P=delim)/U', $input, $matches)) {
$this->not_intitle = $matches['search'];
$input = str_replace($matches[0], '', $input);
@@ -414,16 +395,11 @@ class FreshRSS_Search {
}
/**
- * Parse the search string to find author keyword and the search related
- * to it.
+ * Parse the search string to find author keyword and the search related to it.
* The search is the first word following the keyword except when using
- * a delimiter. Supported delimiters are single quote (') and double
- * quotes (").
- *
- * @param string $input
- * @return string
+ * a delimiter. Supported delimiters are single quote (') and double quotes (").
*/
- private function parseAuthorSearch($input) {
+ private function parseAuthorSearch(string $input): string {
if (preg_match_all('/\bauthor:(?P<delim>[\'"])(?P<search>.*)(?P=delim)/U', $input, $matches)) {
$this->author = $matches['search'];
$input = str_replace($matches[0], '', $input);
@@ -436,7 +412,7 @@ class FreshRSS_Search {
return $input;
}
- private function parseNotAuthorSearch($input) {
+ private function parseNotAuthorSearch(string $input): string {
if (preg_match_all('/[!-]author:(?P<delim>[\'"])(?P<search>.*)(?P=delim)/U', $input, $matches)) {
$this->not_author = $matches['search'];
$input = str_replace($matches[0], '', $input);
@@ -450,14 +426,10 @@ class FreshRSS_Search {
}
/**
- * Parse the search string to find inurl keyword and the search related
- * to it.
+ * Parse the search string to find inurl keyword and the search related to it.
* The search is the first word following the keyword.
- *
- * @param string $input
- * @return string
*/
- private function parseInurlSearch($input) {
+ private function parseInurlSearch(string $input): string {
if (preg_match_all('/\binurl:(?P<search>[^\s]*)/', $input, $matches)) {
$this->inurl = $matches['search'];
$input = str_replace($matches[0], '', $input);
@@ -466,7 +438,7 @@ class FreshRSS_Search {
return $input;
}
- private function parseNotInurlSearch($input) {
+ private function parseNotInurlSearch(string $input): string {
if (preg_match_all('/[!-]inurl:(?P<search>[^\s]*)/', $input, $matches)) {
$this->not_inurl = $matches['search'];
$input = str_replace($matches[0], '', $input);
@@ -476,14 +448,10 @@ class FreshRSS_Search {
}
/**
- * Parse the search string to find date keyword and the search related
- * to it.
+ * Parse the search string to find date keyword and the search related to it.
* The search is the first word following the keyword.
- *
- * @param string $input
- * @return string
*/
- private function parseDateSearch($input) {
+ private function parseDateSearch(string $input): string {
if (preg_match_all('/\bdate:(?P<search>[^\s]*)/', $input, $matches)) {
$input = str_replace($matches[0], '', $input);
$dates = self::removeEmptyValues($matches['search']);
@@ -494,7 +462,7 @@ class FreshRSS_Search {
return $input;
}
- private function parseNotDateSearch($input) {
+ private function parseNotDateSearch(string $input): string {
if (preg_match_all('/[!-]date:(?P<search>[^\s]*)/', $input, $matches)) {
$input = str_replace($matches[0], '', $input);
$dates = self::removeEmptyValues($matches['search']);
@@ -507,14 +475,10 @@ class FreshRSS_Search {
/**
- * Parse the search string to find pubdate keyword and the search related
- * to it.
+ * Parse the search string to find pubdate keyword and the search related to it.
* The search is the first word following the keyword.
- *
- * @param string $input
- * @return string
*/
- private function parsePubdateSearch($input) {
+ private function parsePubdateSearch(string $input): string {
if (preg_match_all('/\bpubdate:(?P<search>[^\s]*)/', $input, $matches)) {
$input = str_replace($matches[0], '', $input);
$dates = self::removeEmptyValues($matches['search']);
@@ -525,7 +489,7 @@ class FreshRSS_Search {
return $input;
}
- private function parseNotPubdateSearch($input) {
+ private function parseNotPubdateSearch(string $input): string {
if (preg_match_all('/[!-]pubdate:(?P<search>[^\s]*)/', $input, $matches)) {
$input = str_replace($matches[0], '', $input);
$dates = self::removeEmptyValues($matches['search']);
@@ -540,11 +504,8 @@ class FreshRSS_Search {
* Parse the search string to find tags keyword (# followed by a word)
* and the search related to it.
* The search is the first word following the #.
- *
- * @param string $input
- * @return string
*/
- private function parseTagsSearch($input) {
+ private function parseTagsSearch(string $input): string {
if (preg_match_all('/#(?P<search>[^\s]+)/', $input, $matches)) {
$this->tags = $matches['search'];
$input = str_replace($matches[0], '', $input);
@@ -554,7 +515,7 @@ class FreshRSS_Search {
return $input;
}
- private function parseNotTagsSearch($input) {
+ private function parseNotTagsSearch(string $input): string {
if (preg_match_all('/[!-]#(?P<search>[^\s]+)/', $input, $matches)) {
$this->not_tags = $matches['search'];
$input = str_replace($matches[0], '', $input);
@@ -568,10 +529,9 @@ class FreshRSS_Search {
* Parse the search string to find search values.
* Every word is a distinct search value, except when using a delimiter.
* Supported delimiters are single quote (') and double quotes (").
- *
- * @param string $input
+ * @return void
*/
- private function parseSearch($input) {
+ private function parseSearch(string $input) {
$input = self::cleanSearch($input);
if ($input == '') {
return;
@@ -591,17 +551,17 @@ class FreshRSS_Search {
}
}
- private function parseNotSearch($input) {
+ private function parseNotSearch(string $input): string {
$input = self::cleanSearch($input);
if ($input == '') {
- return;
+ return '';
}
if (preg_match_all('/[!-](?P<delim>[\'"])(?P<search>.*)(?P=delim)/U', $input, $matches)) {
$this->not_search = $matches['search'];
$input = str_replace($matches[0], '', $input);
}
if ($input == '') {
- return;
+ return '';
}
if (preg_match_all('/[!-](?P<search>[^\s]+)/', $input, $matches)) {
$this->not_search = array_merge(is_array($this->not_search) ? $this->not_search : array(), $matches['search']);
@@ -613,11 +573,8 @@ class FreshRSS_Search {
/**
* Remove all unnecessary spaces in the search
- *
- * @param string $input
- * @return string
*/
- private static function cleanSearch($input) {
+ private static function cleanSearch(string $input): string {
$input = preg_replace('/\s+/', ' ', $input);
return trim($input);
}