opencart / opencart

A free shopping cart system. OpenCart is an open source PHP-based online e-commerce solution.

Home Page:https://www.opencart.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[3.0.x.x] phpstan requires function signatures to be uniqly identifed across the project

mhcwebdesign opened this issue · comments

Ever since the phpstan runs on github after each pull-request it keeps showing conflicting results for the 3.0.x.x branch.

For example, this one: https://github.com/mhcwebdesign/opencart/actions/runs/7855632559
as opposed to this one: https://github.com/opencart/opencart/actions/runs/7855612207

Running the same level 1 tests on my local test server reports no errors at all for any of the supported PHP versions.

Can we please remove phpstan from github and replace it with a more reliable alternative? If none exists, I'll just set it back to level 0 for 3.0.x.x and simply ignore it for future maintenance work.

I also noticed running phpstan on my local test server multiple times, for the same 3.0.x.x, no changed files, and changed PHP version, can result in different errors being reported after each run, you expect it for each run to come up with the same results.

The issue is caused by there being multiple identically identified functions in OC3 that do not match there signatures:

public function sendCurl($url, $payment_data, $i = null) {

public function sendCurl($url, $payment_data) {

Both classes are called ModelExtensionPaymentOpayo without a namespace.

You will get different results depending on which is processed first by your system.

Basically there are 3 solution:
A: Add namespaces to classes to avoid collisions, this is what OC4 does, but probably not viable for OC3
B: Make identically identified functions have the same signature (see #13665)
C: Rename the conflicting functions or class so the different signatures have unique identifiers (see #13667).

It seems like you think that PHPStan needs all methods with the same name to have the same signature in a project. That's not true, see this proof: https://phpstan.org/r/c73d7686-9759-42e1-8ce0-c83ad96a8177

The problem is that you have two classes with the same name, and different sendCurl signatures. You need to make your class names unique, or make the signatures the same.

It seems like you think that PHPStan needs all methods with the same name to have the same signature in a project. That's not true, see this proof: https://phpstan.org/r/c73d7686-9759-42e1-8ce0-c83ad96a8177

That's not what I said.

The problem is that you have two classes with the same name, and different sendCurl signatures. You need to make your class names unique, or make the signatures the same.

This is not the issue. Class names can be the same as long one belongs to the catalog frontend, and the other to the admin backend of OpenCart 3.0.x.x. phpstan is unable to distinguish between the two, because it doesn't use a proper php parser. It would easy enough to make a distinction between admin and backend by merely taking into account the different path names, e.g.

admin/model/extension/payment/opayo.php

vs

catalog/model/extension/payment/opayo.php

Same class name ModelExtensionPaymentOpayo, but different paths!

If this tool is unable to distinguish between the two, then it should be fixed, or should be run separately for each of admin and catalog.

Also, phpstan should not produce lottery-style results for identical set of PHP files and PHP versions.