Skip to content

Commit

Permalink
[Digikey provider] Do not try to interpret certain parameters (like p…
Browse files Browse the repository at this point in the history
…ackages) as numbers

This fixes issue #682
  • Loading branch information
jbtronics committed Sep 9, 2024
1 parent ddd7252 commit 86d3f87
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/Services/InfoProviderSystem/Providers/DigikeyProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ class DigikeyProvider implements InfoProviderInterface

private readonly HttpClientInterface $digikeyClient;

/**
* A list of parameter IDs, that are always assumed as text only and will never be converted to a numerical value.
* This allows to fix issues like #682, where the "Supplier Device Package" was parsed as a numerical value.
*/
private const TEXT_ONLY_PARAMETERS = [
1291, //Supplier Device Package
39246, //Package / Case
];

public function __construct(HttpClientInterface $httpClient, private readonly OAuthTokenManager $authTokenManager,
private readonly string $currency, private readonly string $clientId,
Expand Down Expand Up @@ -214,7 +222,12 @@ private function parametersToDTOs(array $parameters, string|null &$footprint_nam
continue;
}

$results[] = ParameterDTO::parseValueIncludingUnit($parameter['Parameter'], $parameter['Value']);
//If the parameter was marked as text only, then we do not try to parse it as a numerical value
if (in_array($parameter['ParameterId'], self::TEXT_ONLY_PARAMETERS, true)) {
$results[] = new ParameterDTO(name: $parameter['Parameter'], value_text: $parameter['Value']);
} else { //Otherwise try to parse it as a numerical value
$results[] = ParameterDTO::parseValueIncludingUnit($parameter['Parameter'], $parameter['Value']);
}
}

return $results;
Expand Down

0 comments on commit 86d3f87

Please sign in to comment.