language = strtolower(trim($language)) ?: '*'; $this->country = strtoupper(trim($country)) ?: '*'; } public function getLanguage(): string { return $this->language; } public function getCountry(): string { return $this->country; } public function rank(array $providers, string $domain, string $identifierType): array { $preferred = $this->preferredOrder($domain, $identifierType); usort($providers, static function (ProviderDescriptor $left, ProviderDescriptor $right) use ($preferred): int { $leftIndex = array_search($left->getName(), $preferred, true); $rightIndex = array_search($right->getName(), $preferred, true); $leftRank = $leftIndex === false ? PHP_INT_MAX : $leftIndex; $rightRank = $rightIndex === false ? PHP_INT_MAX : $rightIndex; return ($leftRank <=> $rightRank) ?: ($right->getPriority() <=> $left->getPriority()) ?: ($right->getStatistics()->getOverallScore() <=> $left->getStatistics()->getOverallScore()) ?: strcasecmp($left->getName(), $right->getName()); }); return array_values($providers); } public function calculateConfidence( ProviderDescriptor $provider, float $identifierConfidence, float $domainConfidence ): float { $score = ($identifierConfidence * 0.25) + ($domainConfidence * 0.20) + ($provider->getStatistics()->getOverallScore() * 0.25) + ($provider->getReliability() * 0.20) + (($provider->getPriority() / 100) * 0.10); return round(max(0.0, min(1.0, $score)), 4); } public function estimateExecutionCost(ProviderDescriptor $provider): float { $authenticationCost = $provider->getAuthentication() === 'none' ? 0.0 : 0.15; return round(max(0.0, min(1.0, (1 - $provider->getEstimatedSpeed()) + $authenticationCost)), 4); } private function preferredOrder(string $domain, string $identifierType): array { return \TFGraphics\SmartImport\Providers\Foundation\RuntimeProviderCatalog::policy('preferred_orders')[$domain][$identifierType] ?? []; } }