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

Analyze most of the source code with phpstan. Provide baseline. #2035

Merged
merged 1 commit into from
Apr 21, 2022

Conversation

tmotyl
Copy link
Contributor

@tmotyl tmotyl commented Mar 8, 2022

This patch makes phpstan analyze almost whole OpenMage source code.
To make the phpstan green despite not all issues are yet solved,
a baseline file is introduced, which contains "known issues".
Thanks to this approach we can make sure new changes
are not introducing new issues, and its easy to fix issues from baseline
one by one.

This patch also fixes some issues along the way:

  1. deprecate _getHelper method from Mage_Adminhtml_Controller_Rss_Abstract
    as it had incompatible interface with parent class, and was used only in one place.
  2. Fix non existing class name Mage_Catalog_Model_Entity_Product_Collection
    with correct one Mage_Catalog_Model_Resource_Product_Collection
  3. Correct casing of the class name Zend_Pdf_Color_Rgb
  4. few minor phpdocs changes
  5. update macopedia/phpstan-magento1 to newest version which brings
    performance improvements
  6. add #[\ReturnTypeWillChange] in some places to avoid errors on php8.1

Description (*)

Related Pull Requests

Fixed Issues (if relevant)

  1. Fixes Add ability to run PHPStan  #365
  2. Fixes Detect undefined functions on PullRequests #1087

Manual testing scenarios (*)

  1. ...
  2. ...

Questions or comments

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All automated tests passed successfully (all builds are green)
  • Add yourself to contributors list

@tmotyl tmotyl requested review from Flyingmana and sreichel and removed request for Flyingmana March 8, 2022 08:09
@github-actions github-actions bot added Component: Adminhtml Relates to Mage_Adminhtml Component: Catalog Relates to Mage_Catalog Component: ImportExport Relates to Mage_ImportExport Component: Sales Relates to Mage_Sales composer Relates to composer.json environment labels Mar 8, 2022
@tmotyl
Copy link
Contributor Author

tmotyl commented Mar 8, 2022

interestingly, here on github phpstan finds more issues then running locally. I'm investigating

@tmotyl
Copy link
Contributor Author

tmotyl commented Mar 8, 2022

mystery solved, its due to php version. locally I run it with 7.4 and github runs 8.1

@github-actions github-actions bot added the Component: Api PageRelates to Mage_Api label Mar 8, 2022
@tmotyl
Copy link
Contributor Author

tmotyl commented Mar 8, 2022

looks good now

@sreichel
Copy link
Contributor

sreichel commented Mar 9, 2022

I'd keep _getHelper() method. It could be used in 3rd party code.

Maybe mark it as deprecated and ignore it from sniffs?

@tmotyl
Copy link
Contributor Author

tmotyl commented Mar 9, 2022

I'd keep _getHelper() method. It could be used in 3rd party code.

Maybe mark it as deprecated and ignore it from sniffs?

This issue cant be ignored afaik, only whole file can be skipped.
Alternatively i can keep the method but remove the param and make it always return rss helper? This would make it less breaking

This patch makes phpstan analyze almost whole OpenMage source code.
To make the phpstan green despite not all issues are yet solved,
a baseline file is introduced, which contains "known issues".
Thanks to this approach we can make sure new changes
are not introducing new issues, and its easy to fix issues from baseline
one by one.

This patch also fixes some issues along the way:

1. Fix non existing class name Mage_Catalog_Model_Entity_Product_Collection
with correct one Mage_Catalog_Model_Resource_Product_Collection
2. Correct casing of the class name Zend_Pdf_Color_Rgb
3. few minor phpdocs changes
4. update macopedia/phpstan-magento1 to newest version which brings
performance improvements
5. add #[\ReturnTypeWillChange] in some places to avoid errors on php8.1
@tmotyl
Copy link
Contributor Author

tmotyl commented Mar 9, 2022

@sreichel I've excluded the RSS files from analysing and deprecated the method. We might want to remove this method in v20 branch. but this will be a different patch.

@tmotyl
Copy link
Contributor Author

tmotyl commented Mar 9, 2022

FYI, once we have this one merged, I have a bunch of patches ready on top of it, which lowers down number of issues and rise the phpstan level to 1.
A little teaser:
image

@sreichel
Copy link
Contributor

sreichel commented Mar 10, 2022

FYI, once we have this one merged, I have a bunch of patches ready on top of it,

NICE! Thanks for your effort. ❤️

Not ready for PR, i already tried to bring it to level 2,3 or 4 as where it is possible :)

(not sure if #784 is up2date ... guess not)

@tmotyl tmotyl requested a review from colinmollenhour March 17, 2022 12:47
@tmotyl tmotyl requested a review from fballiano April 21, 2022 06:31
@tmotyl tmotyl merged commit 3dc7e68 into OpenMage:1.9.4.x Apr 21, 2022
@github-actions
Copy link
Contributor

Unit Test Results

1 files  ±0  1 suites  ±0   0s ⏱️ ±0s
0 tests ±0  0 ✔️ ±0  0 💤 ±0  0 ❌ ±0 
7 runs  ±0  5 ✔️ ±0  2 💤 ±0  0 ❌ ±0 

Results for commit 3dc7e68. ± Comparison against base commit 8e9ac45.

@tmotyl tmotyl deleted the update-phpstan branch April 21, 2022 20:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Adminhtml Relates to Mage_Adminhtml Component: Api PageRelates to Mage_Api Component: Catalog Relates to Mage_Catalog Component: ImportExport Relates to Mage_ImportExport Component: Sales Relates to Mage_Sales composer Relates to composer.json environment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Detect undefined functions on PullRequests Add ability to run PHPStan
3 participants