Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

phpstan: Mage_Poll #2816

Merged
merged 1 commit into from
Dec 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions app/code/core/Mage/Poll/Block/ActivePoll.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions app/code/core/Mage/Poll/Model/Poll.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down
4 changes: 2 additions & 2 deletions app/code/core/Mage/Poll/Model/Resource/Poll.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
50 changes: 0 additions & 50 deletions phpstan.dist.baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down