Skip to content

Commit

Permalink
Link::getAdminLink - check type of $params param
Browse files Browse the repository at this point in the history
Thirty bees 1.4.0 added new parameter $params to the method
Link::getAdminLink() with default value.

While this should be backwards compatible change, it still causes
problems.

Some module called Link::getAdminLink() with third paramter already.
This parameter used to be ignored, but now it can cause type errors.

This commit adds type check -- if the $params parameter is not array, we
raise warning and initialize the parameter to empty array.

In the future, this check will be replaced with an actual error message
(by adding array to method signature)
  • Loading branch information
getdatakick committed Dec 17, 2022
1 parent 949b4cb commit 125bc30
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions classes/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,16 @@ public function getAdminLink($controller, $withToken = true, $params = [])
{
$idLang = Context::getContext()->language->id;

if (! is_array($params)) {
$callPoint = Tools::getCallPoint([Link::class]);
$errorMessage = 'Link::getAdminLink(): parameter $params has invalid type. ';
$errorMessage .= 'Expected array, got ' . gettype($params) . '. ';
$errorMessage .= 'This will raise error in future version of thirty bees. ';
$errorMessage .= 'Called from: ' . $callPoint['class'] . '::' . $callPoint['function'] . '() in ' . $callPoint['file'] . ':' . $callPoint['line'];
trigger_error($errorMessage, E_USER_WARNING);
$params = [];
}

if ($withToken) {
$params['token'] = Tools::getAdminTokenLite($controller);
}
Expand Down

0 comments on commit 125bc30

Please sign in to comment.