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

Fixed phpstan in Mage/Customer/controllers/AccountController.php #3750

Merged
merged 11 commits into from
Feb 21, 2024

Conversation

kiatng
Copy link
Contributor

@kiatng kiatng commented Jan 23, 2024

But I am not sure about this

			message: "#^Method Mage_Customer_AccountController\\:\\:preDispatch\\(\\) should return \\$this\\(Mage_Customer_AccountController\\) but empty return statement found\\.$#"
			count: 1
			path: app/code/core/Mage/Customer/controllers/AccountController.php

/**
* Action predispatch
*
* Check customer authentication for some actions
*/
public function preDispatch()
{
// @todo a brute-force protection here would be nice
parent::preDispatch();
if (!$this->getRequest()->isDispatched()) {
return;
}

@github-actions github-actions bot added Component: Customer Relates to Mage_Customer phpstan labels Jan 23, 2024
@sreichel
Copy link
Contributor

But I am not sure about this

I think return $this should be okay.

@luigifab
Copy link
Contributor

I vote to mark _getModel methods as deprecated to use getModel directly.

@sreichel
Copy link
Contributor

_getModel() offered the ability to add custom logic w/o overriding alls methods, where it was used.

Not sure if it is a good change,

@kiatng
Copy link
Contributor Author

kiatng commented Jan 29, 2024

In case _getModel() is used or overriden by 3rd-party code with custom logic, the only issue I can think of is that the IDE would complain about deprecated function, other than that, it shouldn't cause any problem. Or am I wrong?

@sreichel
Copy link
Contributor

@kiatng not sure if it is a real use-case, but you could rewrite _getModel() to something like ...

    public function _getModel($path, $arguments = [])
    {
        if ($path === 'customer/customer') {
            // change arguments or something else
        }
        return Mage::getModel($path, $arguments);
    }

... and it would work for every method. With this change you have to override all methods that used _getModel() befor.

@kiatng
Copy link
Contributor Author

kiatng commented Jan 31, 2024

@sreichel I am just trying to fix the complaints of my IDE, vscode + PHP Intelephense, complaining about undefined method $customer->sendNewAccountEmail(). And it so happens that it's PHPStan related. I do think that _getModel() is unnecessary.

@sreichel
Copy link
Contributor

sreichel commented Jan 31, 2024

@kiatng whats wrong with adding /** @var Mage_Customer_Model_Customer $customer **/ or even better check for instanceof?

Finally i agree with it, but its not what i prefer.

@fballiano
Copy link
Contributor

If we remove the _getModel method I think this should be considered breaking change because it would break overridden code, although it's something probably nobody did. So I'd just add /** @var Mage_Customer_Model_Customer $customer **/ if that solved the problem.

@kiatng
Copy link
Contributor Author

kiatng commented Feb 7, 2024

If we remove the _getModel method I think this should be considered breaking change because it would break overridden code, although it's something probably nobody did.

I agree _getModel() shouldn't be removed. At the same time, it's not a very useful function. So in this PR, it is deprecated:
image

@ADDISON74
Copy link
Contributor

ADDISON74 commented Feb 21, 2024

ubuntu@DESKTOP-GBHMUPN:~/openmage$ ddev phpstan -l4 /var/www/html/app/code/core/Mage/Customer/controllers/AccountController.php
Note: Using configuration file /var/www/html/phpstan.dist.neon.
 1/1 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
 [OK] No errors

Starting with level 5, there are 3 errors, then with each level more and more. I haven't checked what PHPStan level we have set for OpenMage at this moment, but I think this PR will pass it.

@kiatng kiatng merged commit 1834708 into OpenMage:main Feb 21, 2024
17 checks passed
@kiatng kiatng deleted the phpstan_accountController branch February 21, 2024 10:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Customer Relates to Mage_Customer phpstan
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants