Upgrade phpstan to v2

This commit is contained in:
crazywhalecc
2026-02-03 11:22:32 +08:00
parent c536fedff7
commit 103b5b3585
9 changed files with 162 additions and 159 deletions

View File

@@ -241,7 +241,6 @@ class php extends TargetPackage
{
$arg = [];
foreach ($installer->getResolvedPackages() as $package) {
/** @var PhpExtensionPackage $package */
if ($package->getType() !== 'php-extension' || !$package instanceof PhpExtensionPackage) {
continue;
}

View File

@@ -312,7 +312,7 @@ class ArtifactDownloader
FileSystem::createDir(DOWNLOAD_PATH);
}
logger()->info('Downloading' . implode(', ', array_map(fn ($x) => " '{$x->getName()}'", $this->artifacts)) . " with concurrency {$this->parallel} ...");
// Download artifacts parallely
// Download artifacts parallelly
if ($this->parallel > 1) {
$this->downloadWithConcurrency();
} else {

View File

@@ -247,6 +247,7 @@ class ArtifactExtractor
$artifact->emitAfterBinaryExtract($target_path, $platform);
logger()->debug("Emitted after-binary-extract hooks for [{$name}]");
/* @phpstan-ignore-next-line */
if ($hash !== null && $cache_info['cache_type'] !== 'file') {
FileSystem::writeFile("{$target_path}/.spc-hash", $hash);
}

View File

@@ -169,7 +169,7 @@ class PackageLoader
}
}
$pkg = self::$packages[$attribute_instance->name];
$pkg = self::$packages[$attribute_instance->name] ?? null;
// Use the package instance if it's a Package subclass, otherwise create a new instance
$instance_class = is_a($class_name, Package::class, true) ? $pkg : $refClass->newInstance();
@@ -184,7 +184,7 @@ class PackageLoader
if (!in_array($package_type, $pkg_type_attr, true)) {
throw new RegistryException("Package [{$attribute_instance->name}] type mismatch: config type is [{$package_type}], but attribute type is [" . implode('|', $pkg_type_attr) . '].');
}
if ($pkg !== null && !PackageConfig::isPackageExists($pkg->getName())) {
if ($pkg instanceof Package && !PackageConfig::isPackageExists($pkg->getName())) {
throw new RegistryException("Package [{$pkg->getName()}] config not found for class {$class}");
}
@@ -355,7 +355,7 @@ class PackageLoader
$stage = $method_instance->stage;
$stage = match (true) {
is_string($stage) => $stage,
is_array($stage) && count($stage) === 2 => $stage[1],
count($stage) === 2 => $stage[1],
default => throw new RegistryException('Invalid stage definition in BeforeStage attribute.'),
};
if ($method_instance->package_name === '' && $pkg === null) {

View File

@@ -75,7 +75,7 @@ class LicenseDumper
*
* @param Artifact $artifact Artifact instance
* @param string $target_dir Target directory
* @param array<string, array> &$license_summary Summary data to populate
* @param array &$license_summary Summary data to populate
* @return bool True if dumped
* @throws SPCInternalException
*/

View File

@@ -44,7 +44,7 @@ abstract class UnixUtil
continue;
}
$name = preg_replace('/@.*$/', '', $name);
if ($name !== '' && $name !== false) {
if (!empty($name)) {
$defined[] = $name;
}
}