diff --git a/app/code/core/Mage/Poll/Block/ActivePoll.php b/app/code/core/Mage/Poll/Block/ActivePoll.php index 2d180ba0469..6947f36e36c 100644 --- a/app/code/core/Mage/Poll/Block/ActivePoll.php +++ b/app/code/core/Mage/Poll/Block/ActivePoll.php @@ -144,8 +144,8 @@ public function getPollData($pollId) if (empty($pollId)) { return false; } - $poll = $this->_pollModel->load($pollId); + $poll = $this->_pollModel->load($pollId); $pollAnswers = Mage::getModel('poll/poll_answer') ->getResourceCollection() ->addPollFilter($pollId) @@ -155,6 +155,8 @@ public function getPollData($pollId) // correct rounded percents to be always equal 100 $percentsSorted = []; $answersArr = []; + $key = null; + /** * @var int $key * @var Mage_Poll_Model_Poll_Answer $answer @@ -163,11 +165,15 @@ public function getPollData($pollId) $percentsSorted[$key] = $answer->getPercent(); $answersArr[$key] = $answer; } - asort($percentsSorted); + $total = 0; + $value = 0; + + asort($percentsSorted); foreach ($percentsSorted as $key => $value) { $total += $value; } + // change the max value only if ($total > 0 && $total !== 100) { $answersArr[$key]->setPercent($value + 100 - $total); diff --git a/app/code/core/Mage/Poll/Model/Poll.php b/app/code/core/Mage/Poll/Model/Poll.php index 149c0e7efcd..cca707a88ea 100644 --- a/app/code/core/Mage/Poll/Model/Poll.php +++ b/app/code/core/Mage/Poll/Model/Poll.php @@ -104,8 +104,8 @@ public function getPoolId($pollId = null) /** * Retrieve defined or current Id * - * @param string $pollId - * @return string + * @param int|string|null $pollId + * @return int|string */ public function getPollId($pollId = null) { @@ -202,8 +202,8 @@ public function addVote(Mage_Poll_Model_Poll_Vote $vote) /** * Check answer existing for poll * - * @param mixed $answer - * @return bool + * @param Mage_Poll_Model_Poll_Answer|string|int $answer + * @return string|false */ public function hasAnswer($answer) { diff --git a/app/code/core/Mage/Poll/Model/Resource/Poll.php b/app/code/core/Mage/Poll/Model/Resource/Poll.php index 9df6399dcc6..305b51c1579 100644 --- a/app/code/core/Mage/Poll/Model/Resource/Poll.php +++ b/app/code/core/Mage/Poll/Model/Resource/Poll.php @@ -85,7 +85,7 @@ protected function _getSelectIds($object) * Get random identifier not closed poll * * @param Mage_Poll_Model_Poll $object - * @return int + * @return string */ public function getRandomId($object) { @@ -110,7 +110,7 @@ public function getAllIds($object) * * @param Mage_Poll_Model_Poll $poll * @param int $answerId - * @return bool + * @return string */ public function checkAnswerId($poll, $answerId) { diff --git a/app/code/core/Mage/Poll/Model/Resource/Poll/Answer/Collection.php b/app/code/core/Mage/Poll/Model/Resource/Poll/Answer/Collection.php index 94b29e582be..88c749ad0fc 100644 --- a/app/code/core/Mage/Poll/Model/Resource/Poll/Answer/Collection.php +++ b/app/code/core/Mage/Poll/Model/Resource/Poll/Answer/Collection.php @@ -58,7 +58,7 @@ public function addPollFilter($pollId) public function countPercent($pollObject) { if (!$pollObject) { - return; + return $this; } else { foreach ($this->getItems() as $answer) { $answer->countPercent($pollObject); diff --git a/phpstan.dist.baseline.neon b/phpstan.dist.baseline.neon index 6e3c6963e99..266163941fc 100644 --- a/phpstan.dist.baseline.neon +++ b/phpstan.dist.baseline.neon @@ -11150,56 +11150,6 @@ parameters: count: 2 path: app/code/core/Mage/Persistent/Model/Observer.php - - - message: "#^Variable \\$key might not be defined\\.$#" - count: 1 - path: app/code/core/Mage/Poll/Block/ActivePoll.php - - - - message: "#^Variable \\$value might not be defined\\.$#" - count: 1 - path: app/code/core/Mage/Poll/Block/ActivePoll.php - - - - message: "#^Method Mage_Poll_Model_Poll\\:\\:getPoolId\\(\\) should return int but returns string\\.$#" - count: 1 - path: app/code/core/Mage/Poll/Model/Poll.php - - - - message: "#^Method Mage_Poll_Model_Poll\\:\\:getRandomId\\(\\) should return string but returns int\\.$#" - count: 1 - path: app/code/core/Mage/Poll/Model/Poll.php - - - - message: "#^Parameter \\#1 \\$pollId of method Mage_Poll_Model_Poll\\:\\:getCookieName\\(\\) expects int\\|null, string given\\.$#" - count: 1 - path: app/code/core/Mage/Poll/Model/Poll.php - - - - message: "#^Parameter \\#1 \\$pollId of method Mage_Poll_Model_Poll\\:\\:getPollId\\(\\) expects string\\|null, int\\|null given\\.$#" - count: 4 - path: app/code/core/Mage/Poll/Model/Poll.php - - - - message: "#^Parameter \\#2 \\$pollId of method Mage_Poll_Model_Resource_Poll\\:\\:getVotedPollIdsByIp\\(\\) expects int\\|false, string given\\.$#" - count: 1 - path: app/code/core/Mage/Poll/Model/Poll.php - - - - message: "#^Method Mage_Poll_Model_Resource_Poll\\:\\:checkAnswerId\\(\\) should return bool but returns string\\.$#" - count: 1 - path: app/code/core/Mage/Poll/Model/Resource/Poll.php - - - - message: "#^Method Mage_Poll_Model_Resource_Poll\\:\\:getRandomId\\(\\) should return int but returns string\\.$#" - count: 1 - path: app/code/core/Mage/Poll/Model/Resource/Poll.php - - - - message: "#^Method Mage_Poll_Model_Resource_Poll_Answer_Collection\\:\\:countPercent\\(\\) should return \\$this\\(Mage_Poll_Model_Resource_Poll_Answer_Collection\\) but empty return statement found\\.$#" - count: 1 - path: app/code/core/Mage/Poll/Model/Resource/Poll/Answer/Collection.php - - message: "#^Call to function is_null\\(\\) with Mage_Core_Model_Store will always evaluate to false\\.$#" count: 1