aboutsummaryrefslogtreecommitdiff
path: root/lib
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 /lib
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 'lib')
-rw-r--r--lib/Minz/ExtensionManager.php2
-rw-r--r--lib/Minz/Migrator.php2
-rw-r--r--lib/Minz/Translate.php4
-rw-r--r--lib/Minz/Url.php2
-rw-r--r--lib/lib_phpQuery.php122
-rw-r--r--lib/lib_rss.php4
6 files changed, 66 insertions, 70 deletions
diff --git a/lib/Minz/ExtensionManager.php b/lib/Minz/ExtensionManager.php
index 2b42708f8..cad408aed 100644
--- a/lib/Minz/ExtensionManager.php
+++ b/lib/Minz/ExtensionManager.php
@@ -295,7 +295,7 @@ class Minz_ExtensionManager {
* array keys.
*
* @param string $hook_name the hook to call.
- * @param mixed $args additional parameters (for signature, please see self::$hook_list).
+ * @param mixed ...$args additional parameters (for signature, please see self::$hook_list).
* @return mixed|null final result of the called hook.
*/
public static function callHook($hook_name, ...$args) {
diff --git a/lib/Minz/Migrator.php b/lib/Minz/Migrator.php
index 4d58a9bd3..71abbff3e 100644
--- a/lib/Minz/Migrator.php
+++ b/lib/Minz/Migrator.php
@@ -129,7 +129,7 @@ class Minz_Migrator
public function __construct($directory = null) {
$this->applied_versions = [];
- if (!is_dir($directory)) {
+ if ($directory == null || !is_dir($directory)) {
return;
}
diff --git a/lib/Minz/Translate.php b/lib/Minz/Translate.php
index 4b860259e..19a86a00e 100644
--- a/lib/Minz/Translate.php
+++ b/lib/Minz/Translate.php
@@ -179,7 +179,7 @@ class Minz_Translate {
/**
* Translate a key into its corresponding value based on selected language.
* @param string $key the key to translate.
- * @param mixed $args additional parameters for variable keys.
+ * @param mixed ...$args additional parameters for variable keys.
* @return string value corresponding to the key.
* If no value is found, return the key itself.
*/
@@ -247,7 +247,7 @@ class Minz_Translate {
/**
* Alias for Minz_Translate::t()
* @param string $key
- * @param mixed $args
+ * @param mixed ...$args
*/
function _t($key, ...$args) {
return Minz_Translate::t($key, ...$args);
diff --git a/lib/Minz/Url.php b/lib/Minz/Url.php
index 777962e25..0bbf28b0d 100644
--- a/lib/Minz/Url.php
+++ b/lib/Minz/Url.php
@@ -121,7 +121,7 @@ class Minz_Url {
/**
* @param string $controller
* @param string $action
- * @param string $args
+ * @param string ...$args
*/
function _url ($controller, $action, ...$args) {
$nb_args = count($args);
diff --git a/lib/lib_phpQuery.php b/lib/lib_phpQuery.php
index 29d06749c..f47133235 100644
--- a/lib/lib_phpQuery.php
+++ b/lib/lib_phpQuery.php
@@ -145,7 +145,7 @@ class DOMDocumentWrapper {
public $id;
/**
* @todo Rewrite as method and quess if null.
- * @var unknown_type
+ * @var string
*/
public $contentType = '';
public $xpath;
@@ -157,7 +157,6 @@ class DOMDocumentWrapper {
public $eventsGlobal = array();
/**
* @TODO iframes support http://code.google.com/p/phpquery/issues/detail?id=28
- * @var unknown_type
*/
public $frames = array();
/**
@@ -475,7 +474,7 @@ class DOMDocumentWrapper {
return $contentType[1];
}
protected function charsetFromXML($markup) {
- $matches;
+ $matches = array();
// find declaration
preg_match('@<'.'?xml[^>]+encoding\\s*=\\s*(["|\'])(.*?)\\1@i',
$markup, $matches
@@ -817,8 +816,8 @@ abstract class phpQueryEvents {
* Trigger a type of event on every matched element.
*
* @param DOMNode|phpQueryObject|string $document
- * @param unknown_type $type
- * @param unknown_type $data
+ * @param string $type
+ * @param array<DOMEvent> $data
*
* @TODO exclusive events (with !)
* @TODO global events (test)
@@ -1199,6 +1198,7 @@ class phpQueryObject
protected $elementsInterator = array();
/**
* Iterator interface helper
+ * @var bool
* @access private
*/
protected $valid = false;
@@ -1709,12 +1709,11 @@ class phpQueryObject
*
* In the future, when PHP will support XLS 2.0, then we would do that this way:
* contains(tokenize(@class, '\s'), "something")
- * @param unknown_type $class
- * @param unknown_type $node
- * @return boolean
+ * @param string $class
+ * @param DOMElement $node
* @access private
*/
- protected function matchClasses($class, $node) {
+ protected function matchClasses(string $class, object $node): bool {
// multi-class
if ( mb_strpos($class, '.', 1)) {
$classes = explode('.', substr($class, 1));
@@ -1904,7 +1903,7 @@ class phpQueryObject
if ($execute) {
$this->runQuery($XQuery, $s, 'is');
$XQuery = '';
- if (! $this->length())
+ if (!$this->size())
break;
}
// CLASSES
@@ -1916,7 +1915,7 @@ class phpQueryObject
$XQuery .= '[@class]';
$this->runQuery($XQuery, $s, 'matchClasses');
$XQuery = '';
- if (! $this->length() )
+ if (!$this->size() )
break;
// ~ General Sibling Selector
} else if ($s[0] == '~') {
@@ -1926,7 +1925,7 @@ class phpQueryObject
->siblings(
substr($s, 1)
)->elements;
- if (! $this->length() )
+ if (!$this->size() )
break;
// + Adjacent sibling selectors
} else if ($s[0] == '+') {
@@ -1944,7 +1943,7 @@ class phpQueryObject
if ($test && $this->is($subSelector, $test))
$this->elements[] = $test;
}
- if (! $this->length() )
+ if (!$this->size() )
break;
// PSEUDO CLASSES
} else if ($s[0] == ':') {
@@ -1953,10 +1952,10 @@ class phpQueryObject
$this->runQuery($XQuery);
$XQuery = '';
}
- if (! $this->length())
+ if (!$this->size())
break;
$this->pseudoClasses($s);
- if (! $this->length())
+ if (!$this->size())
break;
// DIRECT DESCENDANDS
} else if ($s == '>') {
@@ -2438,12 +2437,9 @@ class phpQueryObject
}
}
/**
- *
- * @param $value
- * @return unknown_type
* @TODO implement in all methods using passed parameters
*/
- protected static function unQuote($value) {
+ protected static function unQuote(string $value): string {
return $value[0] == '\'' || $value[0] == '"'
? substr($value, 1, -1)
: $value;
@@ -2619,7 +2615,7 @@ class phpQueryObject
*/
public function wrapAllOld($wrapper) {
$wrapper = pq($wrapper)->_clone();
- if (! $wrapper->length() || ! $this->length() )
+ if (!$wrapper->size() || !$this->size() )
return $this;
$wrapper->insertBefore($this->elements[0]);
$deepest = $wrapper->elements[0];
@@ -2636,7 +2632,7 @@ class phpQueryObject
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
*/
public function wrapAll($wrapper) {
- if (! $this->length())
+ if (!$this->size())
return $this;
return phpQuery::pq($wrapper, $this->getDocumentID())
->clone()
@@ -2785,12 +2781,8 @@ class phpQueryObject
$this->elements[] = $oldStack[$num];
return $this->newInstance();
}
- /**
- * Enter description here...
- *
- * @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
- */
- public function size() {
+
+ public function size(): int {
return count($this->elements);
}
/**
@@ -2802,7 +2794,7 @@ class phpQueryObject
public function length() {
return $this->size();
}
- public function count() {
+ public function count(): int {
return $this->size();
}
/**
@@ -3346,15 +3338,10 @@ class phpQueryObject
return $index;
}
/**
- * Enter description here...
- *
- * @param unknown_type $start
- * @param unknown_type $end
- *
- * @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
+ * @return phpQueryObject
* @testme
*/
- public function slice($start, $end = null) {
+ public function slice(int $start, $end = null): object {
// $last = count($this->elements)-1;
// $end = $end
// ? min($end, $last)
@@ -3370,11 +3357,9 @@ class phpQueryObject
);
}
/**
- * Enter description here...
- *
- * @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
+ * @return phpQueryObject
*/
- public function reverse() {
+ public function reverse(): object {
$this->elementsBackup = $this->elements;
$this->elements = array_reverse($this->elements);
return $this->newInstance();
@@ -3418,7 +3403,7 @@ class phpQueryObject
* @return unknown_type
*/
public static function extend($class, $file = null) {
- return $this->plugin($class, $file);
+ return phpQuery::plugin($class, $file);
}
/**
*
@@ -4083,9 +4068,11 @@ class phpQueryObject
// ITERATOR INTERFACE
/**
- * @access private
+ * @return void
+ * @access private
*/
- public function rewind(){
+ #[\ReturnTypeWillChange]
+ public function rewind() {
$this->debug('iterating foreach');
// phpQuery::selectDocument($this->getDocumentID());
$this->elementsBackup = $this->elements;
@@ -4098,15 +4085,19 @@ class phpQueryObject
$this->current = 0;
}
/**
- * @access private
+ * @return DOMElement
+ * @access private
*/
- public function current(){
+ #[\ReturnTypeWillChange]
+ public function current() {
return $this->elementsInterator[ $this->current ];
}
/**
- * @access private
+ * @return mixed
+ * @access private
*/
- public function key(){
+ #[\ReturnTypeWillChange]
+ public function key() {
return $this->current;
}
/**
@@ -4120,6 +4111,7 @@ class phpQueryObject
* @see phpQueryObject::_next()
* @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
*/
+ #[\ReturnTypeWillChange]
public function next($cssSelector = null){
// if ($cssSelector || $this->valid)
// return $this->_next($cssSelector);
@@ -4137,7 +4129,7 @@ class phpQueryObject
/**
* @access private
*/
- public function valid(){
+ public function valid(): bool {
return $this->valid;
}
// ITERATOR INTERFACE END
@@ -4145,25 +4137,32 @@ class phpQueryObject
/**
* @access private
*/
- public function offsetExists($offset) {
+ public function offsetExists($offset): bool {
return $this->find($offset)->size() > 0;
}
/**
- * @access private
+ * @access private
+ * @param mixed $offset
+ * @return mixed
*/
+ #[\ReturnTypeWillChange]
public function offsetGet($offset) {
return $this->find($offset);
}
/**
- * @access private
+ * @return void
+ * @access private
*/
+ #[\ReturnTypeWillChange]
public function offsetSet($offset, $value) {
// $this->find($offset)->replaceWith($value);
$this->find($offset)->html($value);
}
/**
- * @access private
+ * @return void
+ * @access private
*/
+ #[\ReturnTypeWillChange]
public function offsetUnset($offset) {
// empty
throw new Exception("Can't do unset, use array interface only for calling queries and replacing HTML.");
@@ -4277,7 +4276,7 @@ class phpQueryObject
$debug = phpQuery::$debug;
phpQuery::$debug = false;
// print __FILE__.':'.__LINE__."\n";
- var_dump('length', $this->length());
+ var_dump('length', $this->size());
phpQuery::$debug = $debug;
return $this;
}
@@ -4437,8 +4436,6 @@ abstract class phpQuery {
public static $plugins = array();
/**
* List of loaded plugins.
- *
- * @var unknown_type
*/
public static $pluginsLoaded = array();
public static $pluginsMethods = array();
@@ -4721,7 +4718,7 @@ abstract class phpQuery {
$php = preg_replace($regex, '\\1<php><!-- \\3 --></php>', $php);
return $php;
}
- public static function _phpToMarkupCallback($php, $charset = 'utf-8') {
+ public static function _phpToMarkupCallback($m, $charset = 'utf-8') {
return $m[1].$m[2]
.htmlspecialchars("<"."?php".$m[4]."?".">", ENT_QUOTES|ENT_NOQUOTES, $charset)
.$m[5].$m[2];
@@ -5011,7 +5008,6 @@ abstract class phpQuery {
/**
* Checks if $input is HTML string, which has to start with '<'.
*
- * @deprecated
* @param String $input
* @return Bool
* @todo still used ?
@@ -5226,7 +5222,7 @@ abstract class phpQuery {
*
*/
public static function param($data) {
- return http_build_query($data, null, '&');
+ return http_build_query($data, '', '&');
}
public static function get($url, $data = null, $callback = null, $type = null) {
if (!is_array($data)) {
@@ -5354,8 +5350,8 @@ abstract class phpQuery {
public static function getDOMDocument($source) {
if ($source instanceof DOMDOCUMENT)
return $source;
- $source = self::getDocumentID($source);
- return $source
+ $id = self::getDocumentID($source);
+ return $id
? self::$documents[$id]['document']
: null;
}
@@ -5368,7 +5364,7 @@ abstract class phpQuery {
* @return unknown_type
* @link http://docs.jquery.com/Utilities/jQuery.makeArray
*/
- public static function makeArray($obj) {
+ public static function makeArray($object) {
$array = array();
if (is_object($object) && $object instanceof DOMNODELIST) {
foreach($object as $value)
@@ -5467,12 +5463,12 @@ abstract class phpQuery {
}
/**
* Merge 2 phpQuery objects.
- * @param array $one
- * @param array $two
+ * @param phpQueryObject $one
+ * @param phpQueryObject $two
* @protected
* @todo node lists, phpQueryObject
*/
- public static function merge($one, $two) {
+ public static function merge(object $one, object $two): array {
$elements = $one->elements;
foreach($two->elements as $node) {
$exists = false;
diff --git a/lib/lib_rss.php b/lib/lib_rss.php
index 3ba154209..a43bc475f 100644
--- a/lib/lib_rss.php
+++ b/lib/lib_rss.php
@@ -19,10 +19,10 @@ if (COPY_SYSLOG_TO_STDERR) {
/**
* Build a directory path by concatenating a list of directory names.
*
- * @param string $path_parts a list of directory names
+ * @param string ...$path_parts a list of directory names
* @return string corresponding to the final pathname
*/
-function join_path(...$path_parts) {
+function join_path(...$path_parts): string {
return join(DIRECTORY_SEPARATOR, $path_parts);
}