Update PHPStan to 2.1.6

This commit is contained in:
Anders Jenbo 2025-02-24 11:37:02 +01:00
parent 505faa33ad
commit b940d9baf1
3 changed files with 7 additions and 8 deletions

View File

@ -8,14 +8,13 @@ parameters:
paths: paths:
- ./upload/ - ./upload/
excludePaths: excludePaths:
- ./system/storage/vendor/ - ./tools/phpstan/
- ./upload/system/storage/vendor/ - ./upload/system/storage/vendor/
- ./upload/system/storage/cache/ - ./upload/system/storage/cache/
tmpDir: .cache tmpDir: .cache
ignoreErrors: ignoreErrors:
- '#^Access to an undefined property Opencart\\System\\Engine\\Proxy<Opencart\\Catalog\\Model\\Checkout\\Cart>::\$getTotals\.$#' - '#^Access to an undefined property Opencart\\System\\Engine\\Proxy<Opencart\\Catalog\\Model\\Checkout\\Cart>::\$getTotals\.$#'
- '# always exists and is not #' - '# always exists and is not #'
- '#^Call to an undefined method object::[a-zA-Z]+\(\)\.$#'
- '#^Constant [A-Z_]+ not found\.$#' - '#^Constant [A-Z_]+ not found\.$#'
- '#^Empty array passed to foreach\.$#' - '#^Empty array passed to foreach\.$#'
- '# is always (true|false)\.$#' - '# is always (true|false)\.$#'

Binary file not shown.

View File

@ -3,10 +3,10 @@
namespace Tools\PHPStan; namespace Tools\PHPStan;
use Opencart\System\Engine\Registry; use Opencart\System\Engine\Registry;
use PHPStan\Broker\Broker;
use PHPStan\Reflection\ClassReflection; use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\PropertiesClassReflectionExtension; use PHPStan\Reflection\PropertiesClassReflectionExtension;
use PHPStan\Reflection\PropertyReflection; use PHPStan\Reflection\PropertyReflection;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Type\Generic\GenericObjectType; use PHPStan\Type\Generic\GenericObjectType;
use PHPStan\Type\NullType; use PHPStan\Type\NullType;
use PHPStan\Type\ObjectType; use PHPStan\Type\ObjectType;
@ -38,6 +38,8 @@ class RegistryPropertyReflectionExtension implements PropertiesClassReflectionEx
'user' => \Opencart\System\Library\Cart\User::class, 'user' => \Opencart\System\Library\Cart\User::class,
]; ];
public function __construct(private ReflectionProvider $reflectionProvider) {}
public function hasProperty(ClassReflection $classReflection, string $propertyName): bool { public function hasProperty(ClassReflection $classReflection, string $propertyName): bool {
if (!$classReflection->is(Registry::class)) { if (!$classReflection->is(Registry::class)) {
return false; return false;
@ -66,14 +68,12 @@ class RegistryPropertyReflectionExtension implements PropertiesClassReflectionEx
$classType = $this->convertSnakeToStudly($matches[1]); $classType = $this->convertSnakeToStudly($matches[1]);
$commonName = $this->convertSnakeToStudly($matches[2]); $commonName = $this->convertSnakeToStudly($matches[2]);
$broker = Broker::getInstance();
$type = null; $type = null;
foreach (['Admin', 'Catalog', 'Install'] as $domain) { foreach (['Admin', 'Catalog', 'Install'] as $domain) {
$className1 = '\\Opencart\\' . $domain . '\\' . $classType . '\\' . $commonName; $className1 = '\Opencart\\' . $domain . '\\' . $classType . '\\' . $commonName;
$className2 = preg_replace('/\\\\(?=[^\\\\]+$)/', '', $className1, 1); $className2 = preg_replace('/\\\(?=[^\\\]+$)/', '', $className1, 1);
foreach ([$className1, $className2] as $className) { foreach ([$className1, $className2] as $className) {
if ($broker->hasClass($className)) { if ($this->reflectionProvider->hasClass($className)) {
$found = new ObjectType($className); $found = new ObjectType($className);
if ($classType === 'Model') { if ($classType === 'Model') {
$found = new GenericObjectType('\Opencart\System\Engine\Proxy', [$found]); $found = new GenericObjectType('\Opencart\System\Engine\Proxy', [$found]);