Post by JNeuhoff » Sun Feb 11, 2024 12:28 am

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/opencar ... 7855632559
as opposed to this one: https://github.com/opencart/opencart/ac ... 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.

Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig


User avatar
Guru Member

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by BookerE1 » Tue Feb 13, 2024 12:39 pm

JNeuhoff wrote:
Sun Feb 11, 2024 12:28 am
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/DogNeedsBest
as opposed to this one: https://github.com/opencart/opencart/ac ... 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.
Hello, I can see your query, I give you the best of my knowledge answer so please see below and follow the information...

Phpstan is a static analysis tool that can help you find and fix errors in your PHP code. It can also help you improve your code quality, performance, and security. Phpstan can sometimes produce different results in different environments, depending on various factors, such as:
The Phpstan version and configuration
The PHP version and extensions
The Composer dependencies and autoloading
The file system and caching
The operating system and platform

Troubleshoot the conflicting results you try below inst...
Make sure you are using the same phpstan version and configuration on both your local and CI environments. You can check the phpstan version by running phpstan --version and the configuration by looking at the phpstan.neon file or the phpstan section in your composer.json file.
Make sure you are using the same PHP version and extensions on both your local and CI environments. You can check the PHP version by running php -v and the extensions by running php -m.
Make sure you are using the same Composer dependencies and autoloading on both your local and CI environments. You can check the dependencies by looking at the composer.lock file and the autoloading by looking at the vendor/autoload.php file. You can also run composer install or composer update to sync your dependencies and autoloading.
Make sure you are using the same file system and caching on both your local and CI environments. You can check the file system by looking at the file permissions, paths, and case-sensitivity. You can also check the caching by looking at the tmpDir option in your phpstan configuration or the PHPSTAN_CACHE_DIR environment variable. You can also clear the cache by running phpstan clear-result-cache.
Make sure you are using the same operating system and platform on both your local and CI environments. You can check the operating system by running php_uname() and the platform by running php_sapi_name().

I hope my answer is helpful for you, if any query please tell me I am happy to help you...


Best regard,
BookerE1

Newbie

Posts

Joined
Tue Feb 13, 2024 12:25 pm

Post by JNeuhoff » Tue Feb 13, 2024 7:00 pm

Hi BookerE1, thank you for your reply and explanations.

phpstan has indeed some issues producing different results for the same set of PHP files, same PHP version, and same OS. This is the case when running it in multi-threaded mode.

It also gets confused with equally named class files between the OpenCart admin backend and the frontend, it can only deal with that scenario in OpenCart 4 which uses namespaces to distinguish between equally named classes. It cannot deal with that scenario in OpenCart 3.

We have discussed this in detail on github: https://github.com/phpstan/phpstan/issues/10560

For the time being, the only workaround for these phpstan issues on OpenCart 3.0.x.x is to run it 3 times for:
1) OC catalog frontend
2) OC admin backend
3) OC install

Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig


User avatar
Guru Member

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by JNeuhoff » Tue Feb 13, 2024 7:13 pm

I might also add, that PHPstan doesn't appear to make proper use of PHP include and/or require_once statements. E.g. it doesn't correctly process this one from OpenCart's startup.php:

Code: Select all

// Engine
require_once(modification(DIR_SYSTEM . 'engine/model.php'));
.....
function start($application_config) {
	require_once(DIR_SYSTEM . 'framework.php');	
}
A subsequent class instantiation in the OC framework.php is wrongly interpreted by PHPstan:

Code: Select all

// Event
$event = new Event($registry);
where PHPstan doesn't know whether Event refers to OpenCart's Event class, or the standard PHP Event class. This wouldn't be the case had it properly parsed the PHP files and processed the require_once statements.

So yes, you can't always take PHPstan's error messages at face value, there can be quite a few false positives.

I expected a decent analytical tool at least to be able to properly parse PHP code, which I don't think is the case with PHPstan.

Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig


User avatar
Guru Member

Posts

Joined
Wed Dec 05, 2007 3:38 am

Who is online

Users browsing this forum: No registered users and 2 guests