diff options
author | Tim-Hinnerk Heuer <tim@innocraft.com> | 2021-09-28 11:12:50 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-28 11:12:50 +0300 |
commit | 1bc9fdf55352b61c278d298e9935451394230355 (patch) | |
tree | bc2e264fb1bbdf93d6fb9d5c5dd650524afc6b8c | |
parent | 6130619db38b901dfb35f6aeeceedbe6b4e1e0c0 (diff) |
A few more PHP8.1 fixes (#17989)
* add return type declartions #17686
should not break anything and gets rid of a warning
* add return type to method signature #17686
* annotate return types to avoid warnings
* add more return types
* upgrade phpmailer/phpmailer to 6.5.1
* add return types, avoid deprecated null to string conversion
* fix some deprecation warnings for php 8.1 #17686
* fix in DbHelper::getInstallVersion() instead #17686
* ensure empty(DbHelper::getInstallVersion()) succeed #17686
* force return "0" string and adjust test
Co-authored-by: Justin Velluppillai <justin@innocraft.com>
-rw-r--r-- | composer.lock | 18 | ||||
-rw-r--r-- | core/DataTable.php | 10 | ||||
-rw-r--r-- | core/DbHelper.php | 10 | ||||
-rw-r--r-- | libs/Zend/Db/Statement/Pdo.php | 2 | ||||
-rw-r--r-- | libs/Zend/Session/Namespace.php | 2 | ||||
-rw-r--r-- | plugins/DevicePlugins/API.php | 1 | ||||
-rw-r--r-- | plugins/MultiSites/API.php | 1 | ||||
-rw-r--r-- | plugins/Referrers/VisitorDetails.php | 4 | ||||
-rw-r--r-- | plugins/SEO/Metric/Alexa.php | 4 | ||||
-rw-r--r-- | plugins/SEO/Metric/Bing.php | 2 | ||||
-rw-r--r-- | plugins/SEO/Metric/DomainAge.php | 2 | ||||
-rw-r--r-- | plugins/SEO/Metric/Google.php | 2 | ||||
-rw-r--r-- | plugins/SEO/Metric/ProviderCache.php | 2 | ||||
-rw-r--r-- | tests/PHPUnit/Integration/DbHelperTest.php | 3 |
14 files changed, 36 insertions, 27 deletions
diff --git a/composer.lock b/composer.lock index 56df2766fe..0e57d9dbad 100644 --- a/composer.lock +++ b/composer.lock @@ -1436,16 +1436,16 @@ }, { "name": "phpmailer/phpmailer", - "version": "v6.5.0", + "version": "v6.5.1", "source": { "type": "git", "url": "https://github.com/PHPMailer/PHPMailer.git", - "reference": "a5b5c43e50b7fba655f793ad27303cd74c57363c" + "reference": "dd803df5ad7492e1b40637f7ebd258fee5ca7355" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHPMailer/PHPMailer/zipball/a5b5c43e50b7fba655f793ad27303cd74c57363c", - "reference": "a5b5c43e50b7fba655f793ad27303cd74c57363c", + "url": "https://api.github.com/repos/PHPMailer/PHPMailer/zipball/dd803df5ad7492e1b40637f7ebd258fee5ca7355", + "reference": "dd803df5ad7492e1b40637f7ebd258fee5ca7355", "shasum": "" }, "require": { @@ -1457,10 +1457,12 @@ "require-dev": { "dealerdirect/phpcodesniffer-composer-installer": "^0.7.0", "doctrine/annotations": "^1.2", + "php-parallel-lint/php-console-highlighter": "^0.5.0", + "php-parallel-lint/php-parallel-lint": "^1.3", "phpcompatibility/php-compatibility": "^9.3.5", "roave/security-advisories": "dev-latest", - "squizlabs/php_codesniffer": "^3.5.6", - "yoast/phpunit-polyfills": "^0.2.0" + "squizlabs/php_codesniffer": "^3.6.0", + "yoast/phpunit-polyfills": "^1.0.0" }, "suggest": { "ext-mbstring": "Needed to send email in multibyte encoding charset or decode encoded addresses", @@ -1500,7 +1502,7 @@ "description": "PHPMailer is a full-featured email creation and transfer class for PHP", "support": { "issues": "https://github.com/PHPMailer/PHPMailer/issues", - "source": "https://github.com/PHPMailer/PHPMailer/tree/v6.5.0" + "source": "https://github.com/PHPMailer/PHPMailer/tree/v6.5.1" }, "funding": [ { @@ -1508,7 +1510,7 @@ "type": "github" } ], - "time": "2021-06-16T14:33:43+00:00" + "time": "2021-08-18T09:14:16+00:00" }, { "name": "psr/container", diff --git a/core/DataTable.php b/core/DataTable.php index 3442e4ff08..6da6fadaa8 100644 --- a/core/DataTable.php +++ b/core/DataTable.php @@ -1983,29 +1983,29 @@ class DataTable implements DataTableInterface, \IteratorAggregate, \ArrayAccess /** * @return \ArrayIterator|Row[] */ - public function getIterator() + public function getIterator(): \ArrayIterator { return new \ArrayIterator($this->getRows()); } - public function offsetExists($offset) + public function offsetExists($offset): bool { $row = $this->getRowFromId($offset); return false !== $row; } - public function offsetGet($offset) + public function offsetGet($offset): Row { return $this->getRowFromId($offset); } - public function offsetSet($offset, $value) + public function offsetSet($offset, $value): void { $this->rows[$offset] = $value; } - public function offsetUnset($offset) + public function offsetUnset($offset): void { $this->deleteRow($offset); } diff --git a/core/DbHelper.php b/core/DbHelper.php index ea0b4e5e4e..17756acdfc 100644 --- a/core/DbHelper.php +++ b/core/DbHelper.php @@ -118,9 +118,13 @@ class DbHelper /** * Returns which Matomo version was used to install this Matomo for the first time. */ - public static function getInstallVersion() + public static function getInstallVersion(): string { - return Schema::getInstance()->getInstallVersion(); + return Schema::getInstance()->getInstallVersion() ?? '0'; + // need string as usage is usually + // version_compare(DbHelper::getInstallVersion(),'4.0.0-b1', '<') or similar + // and PHP 8.1 throws a deprecation warning otherwise + // @see https://github.com/matomo-org/matomo/pull/17989#issuecomment-921298360 } public static function wasMatomoInstalledBeforeVersion($version) @@ -322,4 +326,4 @@ class DbHelper return (0 !== preg_match('/(^[a-zA-Z0-9]+([a-zA-Z0-9\_\.\-\+]*))$/D', $dbname)); } -} +}
\ No newline at end of file diff --git a/libs/Zend/Db/Statement/Pdo.php b/libs/Zend/Db/Statement/Pdo.php index fb501eaf30..6869582023 100644 --- a/libs/Zend/Db/Statement/Pdo.php +++ b/libs/Zend/Db/Statement/Pdo.php @@ -264,7 +264,7 @@ class Zend_Db_Statement_Pdo extends Zend_Db_Statement implements IteratorAggrega * * @return IteratorIterator */ - public function getIterator() + public function getIterator(): IteratorIterator { return new IteratorIterator($this->_stmt); } diff --git a/libs/Zend/Session/Namespace.php b/libs/Zend/Session/Namespace.php index dfa680233f..d16ed65e45 100644 --- a/libs/Zend/Session/Namespace.php +++ b/libs/Zend/Session/Namespace.php @@ -207,7 +207,7 @@ class Zend_Session_Namespace extends Zend_Session_Abstract implements IteratorAg * * @return ArrayObject - iteratable container of the namespace contents */ - public function getIterator() + public function getIterator(): ArrayObject { return new ArrayObject(parent::_namespaceGetAll($this->_namespace)); } diff --git a/plugins/DevicePlugins/API.php b/plugins/DevicePlugins/API.php index b767d5ade5..99109f72aa 100644 --- a/plugins/DevicePlugins/API.php +++ b/plugins/DevicePlugins/API.php @@ -86,6 +86,7 @@ class API extends \Piwik\Plugin\API $visitsSum = $visitsSumTotal - $ieVisits; $extraProcessedMetrics = $table->getMetadata(DataTable::EXTRA_PROCESSED_METRICS_METADATA_NAME); + $extraProcessedMetrics = is_array($extraProcessedMetrics) ? $extraProcessedMetrics : []; $extraProcessedMetrics[] = new VisitsPercent($visitsSum); $table->setMetadata(DataTable::EXTRA_PROCESSED_METRICS_METADATA_NAME, $extraProcessedMetrics); } diff --git a/plugins/MultiSites/API.php b/plugins/MultiSites/API.php index 5a12e71a0d..a0e20a470c 100644 --- a/plugins/MultiSites/API.php +++ b/plugins/MultiSites/API.php @@ -353,6 +353,7 @@ class API extends \Piwik\Plugin\API ? "Piwik\\Plugins\\MultiSites\\Columns\\Metrics\\EcommerceOnlyEvolutionMetric" : "Piwik\\Plugins\\CoreHome\\Columns\\Metrics\\EvolutionMetric"; + $extraProcessedMetrics = is_array($extraProcessedMetrics) ? $extraProcessedMetrics : []; $extraProcessedMetrics[] = new $evolutionMetricClass( $metricSettings[self::METRIC_RECORD_NAME_KEY], $pastData, diff --git a/plugins/Referrers/VisitorDetails.php b/plugins/Referrers/VisitorDetails.php index df571bf5f3..ece8dc40fe 100644 --- a/plugins/Referrers/VisitorDetails.php +++ b/plugins/Referrers/VisitorDetails.php @@ -94,9 +94,9 @@ class VisitorDetails extends VisitorDetailsAbstract return null; } - protected function getReferrerName() + protected function getReferrerName(): string { - return urldecode($this->details['referer_name']); + return urldecode($this->details['referer_name'] ?? ''); } protected function getSearchEngineUrl() diff --git a/plugins/SEO/Metric/Alexa.php b/plugins/SEO/Metric/Alexa.php index b0d3a42c6b..a9a58160e0 100644 --- a/plugins/SEO/Metric/Alexa.php +++ b/plugins/SEO/Metric/Alexa.php @@ -35,7 +35,7 @@ class Alexa implements MetricsProvider { $value = null; try { - $response = Http::sendHttpRequest(self::URL . urlencode($domain), $timeout = 10, @$_SERVER['HTTP_USER_AGENT']); + $response = Http::sendHttpRequest(self::URL . urlencode($domain ?? ''), $timeout = 10, @$_SERVER['HTTP_USER_AGENT']); libxml_use_internal_errors(true); // suppress errors $dom = new \DomDocument(); $dom->loadHTML($response); @@ -54,7 +54,7 @@ class Alexa implements MetricsProvider } $logo = "plugins/Morpheus/icons/dist/SEO/alexa.com.png"; - $link = self::LINK . urlencode($domain); + $link = self::LINK . urlencode($domain ?? ''); return array( new Metric('alexa', 'SEO_AlexaRank', $value, $logo, $link) diff --git a/plugins/SEO/Metric/Bing.php b/plugins/SEO/Metric/Bing.php index ab7b1bce88..1279b77894 100644 --- a/plugins/SEO/Metric/Bing.php +++ b/plugins/SEO/Metric/Bing.php @@ -32,7 +32,7 @@ class Bing implements MetricsProvider public function getMetrics($domain) { - $url = self::URL . urlencode($domain); + $url = self::URL . urlencode($domain ?? ''); try { $response = str_replace(' ', ' ', Http::sendHttpRequest($url, $timeout = 10, @$_SERVER['HTTP_USER_AGENT'])); diff --git a/plugins/SEO/Metric/DomainAge.php b/plugins/SEO/Metric/DomainAge.php index 8d5d4bc4b8..0753e8eb89 100644 --- a/plugins/SEO/Metric/DomainAge.php +++ b/plugins/SEO/Metric/DomainAge.php @@ -35,7 +35,7 @@ class DomainAge implements MetricsProvider public function getMetrics($domain) { - $domain = str_replace('www.', '', $domain); + $domain = str_replace('www.', '', $domain ?? ''); $ages = array(); diff --git a/plugins/SEO/Metric/Google.php b/plugins/SEO/Metric/Google.php index 2edf5afc23..14f6e3d9f2 100644 --- a/plugins/SEO/Metric/Google.php +++ b/plugins/SEO/Metric/Google.php @@ -46,7 +46,7 @@ class Google implements MetricsProvider public function fetchIndexedPagesCount($domain) { - $url = self::SEARCH_URL . urlencode($domain); + $url = self::SEARCH_URL . urlencode($domain ?? ''); try { $response = str_replace(' ', ' ', Http::sendHttpRequest($url, $timeout = 10, @$_SERVER['HTTP_USER_AGENT'])); diff --git a/plugins/SEO/Metric/ProviderCache.php b/plugins/SEO/Metric/ProviderCache.php index 98b4c08fa0..898a19a6fd 100644 --- a/plugins/SEO/Metric/ProviderCache.php +++ b/plugins/SEO/Metric/ProviderCache.php @@ -34,7 +34,7 @@ class ProviderCache implements MetricsProvider public function getMetrics($domain) { - $cacheId = 'SEO_getRank_' . md5($domain); + $cacheId = 'SEO_getRank_' . md5($domain ?? ''); $metrics = $this->cache->fetch($cacheId); diff --git a/tests/PHPUnit/Integration/DbHelperTest.php b/tests/PHPUnit/Integration/DbHelperTest.php index c08553ea87..57c8d0e7fe 100644 --- a/tests/PHPUnit/Integration/DbHelperTest.php +++ b/tests/PHPUnit/Integration/DbHelperTest.php @@ -40,7 +40,8 @@ class DbHelperTest extends IntegrationTestCase public function test_recordInstallVersion_setsCurrentVersion() { Option::delete(Db\Schema\Mysql::OPTION_NAME_MATOMO_INSTALL_VERSION); - $this->assertNull(DbHelper::getInstallVersion()); + $this->assertEmpty(DbHelper::getInstallVersion()); + $this->assertEquals('0', DbHelper::getInstallVersion()); // since php 8.1 this is required DbHelper::recordInstallVersion(); $this->assertSame(Version::VERSION, DbHelper::getInstallVersion()); |