From 8b63d21a50f2dd4732c51699f911a9fb9bb07132 Mon Sep 17 00:00:00 2001 From: Meirza Date: Tue, 9 May 2023 11:12:19 +0700 Subject: [PATCH] MDL-78165 lib: Added class properties that are not declared in classes In PHP 8.2 and later, setting a value to an undeclared class property is deprecated and emits a deprecation notice. So we need to add missing class properties that still need to be declared. --- lib/classes/analytics/indicator/any_course_access.php | 3 +++ lib/classes/chart_series.php | 2 +- lib/classes/check/access/riskxss_result.php | 6 ++++++ lib/classes/check/result.php | 6 +++--- lib/classes/local/guzzle/cache_handler.php | 6 ++++++ lib/classes/local/guzzle/cache_item.php | 10 +++++----- lib/classes/message/inbound/address_manager.php | 4 +--- lib/classes/plugininfo/base.php | 5 +++++ lib/tests/antivirus_test.php | 2 +- lib/tests/check_test.php | 4 ++-- 10 files changed, 33 insertions(+), 15 deletions(-) diff --git a/lib/classes/analytics/indicator/any_course_access.php b/lib/classes/analytics/indicator/any_course_access.php index 355e382dc02..b8a59e06f07 100644 --- a/lib/classes/analytics/indicator/any_course_access.php +++ b/lib/classes/analytics/indicator/any_course_access.php @@ -35,6 +35,9 @@ defined('MOODLE_INTERNAL') || die(); */ class any_course_access extends \core_analytics\local\indicator\binary { + /** @var array user last access. */ + protected $lastaccesses = []; + /** * Returns the name. * diff --git a/lib/classes/chart_series.php b/lib/classes/chart_series.php index b30fcf78e11..d7a1177e652 100644 --- a/lib/classes/chart_series.php +++ b/lib/classes/chart_series.php @@ -78,7 +78,7 @@ class chart_series implements JsonSerializable { * @return string|null */ public function get_color() { - return isset($this->color[0]) ? $this->color[0] : null; + return isset($this->colors[0]) ? $this->colors[0] : null; } /** diff --git a/lib/classes/check/access/riskxss_result.php b/lib/classes/check/access/riskxss_result.php index adea6bcef29..46191744a53 100644 --- a/lib/classes/check/access/riskxss_result.php +++ b/lib/classes/check/access/riskxss_result.php @@ -45,6 +45,12 @@ use core\check\result; */ class riskxss_result extends \core\check\result { + /** @var array SQL parameters. */ + protected $params = []; + + /** @var string SQL statement. */ + protected $sqlfrom; + /** * Constructor */ diff --git a/lib/classes/check/result.php b/lib/classes/check/result.php index 0710f653885..f3379a3dd35 100644 --- a/lib/classes/check/result.php +++ b/lib/classes/check/result.php @@ -92,9 +92,9 @@ class result implements \renderable { const CRITICAL = 'critical'; /** - * @var string $state - state + * @var string $status - status */ - protected $state = self::UNKNOWN; + protected $status = self::UNKNOWN; /** * @var string summary - should be roughly 1 line of plain text and may change depending on the state. @@ -126,7 +126,7 @@ class result implements \renderable { /** * Constructor * - * @param int $status code + * @param string $status code * @param string $summary a 1 liner summary * @param string $details as a html chunk */ diff --git a/lib/classes/local/guzzle/cache_handler.php b/lib/classes/local/guzzle/cache_handler.php index 7a878a771bb..9310d186a2f 100644 --- a/lib/classes/local/guzzle/cache_handler.php +++ b/lib/classes/local/guzzle/cache_handler.php @@ -44,6 +44,12 @@ class cache_handler { */ private array $deferreditems; + /** @var string module name. */ + private string $module; + + /** @var string the directory for cache. */ + private string $dir; + /** * Constructor for class cache_handler. * This class will accept the module which will determine the location of cached files. diff --git a/lib/classes/local/guzzle/cache_item.php b/lib/classes/local/guzzle/cache_item.php index e6ef8e00657..23ef6d875d4 100644 --- a/lib/classes/local/guzzle/cache_item.php +++ b/lib/classes/local/guzzle/cache_item.php @@ -64,15 +64,15 @@ class cache_item { global $CFG, $USER; $this->key = $key; // Set the directory for cache. - $this->dir = $CFG->cachedir . '/' . $module . '/'; - if (file_exists($this->dir)) { + $dir = $CFG->cachedir . '/' . $module . '/'; + if (file_exists($dir)) { $filename = 'u' . $USER->id . '_' . md5(serialize($key)); // If the cache fine exists, set the value from the cache file. - if (file_exists($this->dir . $filename)) { + if (file_exists($dir . $filename)) { $this->ishit = true; $this->expires_after($ttl); - $fp = fopen($this->dir . $filename, 'rb'); - $size = filesize($this->dir . $filename); + $fp = fopen($dir . $filename, 'rb'); + $size = filesize($dir . $filename); $content = fread($fp, $size); $this->value = unserialize($content); } diff --git a/lib/classes/message/inbound/address_manager.php b/lib/classes/message/inbound/address_manager.php index 0d07227bb01..1f4cb83be47 100644 --- a/lib/classes/message/inbound/address_manager.php +++ b/lib/classes/message/inbound/address_manager.php @@ -435,9 +435,7 @@ class address_manager { $this->process($recipient); // Validate the retrieved data against the e-mail address of the originator. - $this->status = $this->validate($sender); - - return $this->status; + return $this->validate($sender); } /** diff --git a/lib/classes/plugininfo/base.php b/lib/classes/plugininfo/base.php index b7ce65ff9bf..9a73ef77f3c 100644 --- a/lib/classes/plugininfo/base.php +++ b/lib/classes/plugininfo/base.php @@ -77,6 +77,9 @@ abstract class base { /** @var int Move a plugin down in the plugin order */ public const MOVE_DOWN = 1; + /** @var string Name of the plugin */ + public $component; + /** * Whether this plugintype supports its plugins being disabled. * @@ -153,6 +156,7 @@ abstract class base { $plugin->type = $type; $plugin->typerootdir = $typerootdir; $plugin->name = $name; + $plugin->component = $plugin->type.'_'.$plugin->name; $plugin->rootdir = null; $plugin->displayname = $name; $plugin->versiondb = $version; @@ -183,6 +187,7 @@ abstract class base { $plugin->name = $name; $plugin->rootdir = $namerootdir; $plugin->pluginman = $pluginman; + $plugin->component = $plugin->type.'_'.$plugin->name; $plugin->init_display_name(); $plugin->load_disk_version(); diff --git a/lib/tests/antivirus_test.php b/lib/tests/antivirus_test.php index bc4703ea9cd..9367fd1f2d4 100644 --- a/lib/tests/antivirus_test.php +++ b/lib/tests/antivirus_test.php @@ -64,7 +64,7 @@ class antivirus_test extends advanced_testcase { */ protected function get_check_api_antivirus_status_result() { $av = new \core\check\environment\antivirus(); - return $av->get_result()->status; + return $av->get_result()->get_status(); } protected function tearDown(): void { diff --git a/lib/tests/check_test.php b/lib/tests/check_test.php index ab426cbd2df..0acf752eed8 100644 --- a/lib/tests/check_test.php +++ b/lib/tests/check_test.php @@ -44,11 +44,11 @@ class check_test extends \advanced_testcase { $CFG->passwordpolicy = false; $result = $check->get_result(); - $this->assertEquals($result->status, result::WARNING); + $this->assertEquals($result->get_status(), result::WARNING); $CFG->passwordpolicy = true; $result = $check->get_result(); - $this->assertEquals($result->status, result::OK); + $this->assertEquals($result->get_status(), result::OK); $CFG->passwordpolicy = $prior; }