Fix Eldorado text to float conversion and PSR-4

This commit is contained in:
2025-11-06 17:16:36 +01:00
parent ea22c19d2b
commit bcef42b58e
2 changed files with 8 additions and 3 deletions

View File

@@ -1,6 +1,6 @@
<?php <?php
namespace App\Browser\Jobs\HellcaseBattles; namespace App\Browser\Jobs\EldoradoRobuxPriceSentry;
use App\Notification\NotificationBody; use App\Notification\NotificationBody;

View File

@@ -93,11 +93,11 @@ class EldoradoRobuxPriceSentryJob extends BrowserJob implements ShouldBeUniqueUn
{ {
$lowestPriceElement = $browser->driver->findElement(WebDriverBy::xpath('(//eld-offer-price)[2]/strong')); $lowestPriceElement = $browser->driver->findElement(WebDriverBy::xpath('(//eld-offer-price)[2]/strong'));
$lowestPriceText = $lowestPriceElement->getText(); // Ex: " 0,00478 € " $lowestPriceText = $lowestPriceElement->getText(); // Ex: " 0,00478 € "
$lowestPrice = (float)str_replace(["", ","], ["", "."], trim($lowestPriceText)); $lowestPrice = $this->textToFloat($lowestPriceText);
$lowestPrice = $lowestPrice / 1000; // Price per Robux $lowestPrice = $lowestPrice / 1000; // Price per Robux
// TODO : Look at the entire text to try to understand if it is per 1k or per single Robux // TODO : Look at the entire text to try to understand if it is per 1k or per single Robux
$threshold = floatval(str_replace(",", ".", $this->jobInfos->get("eldorado_robux_price_threshold"))); $threshold = $this->textToFloat($this->jobInfos->get("eldorado_robux_price_threshold"));
dump($threshold); dump($threshold);
Log::info("EldoradoRobuxPriceSentryJob: lowest price = $lowestPrice €, threshold = $threshold"); Log::info("EldoradoRobuxPriceSentryJob: lowest price = $lowestPrice €, threshold = $threshold");
@@ -131,4 +131,9 @@ class EldoradoRobuxPriceSentryJob extends BrowserJob implements ShouldBeUniqueUn
Log::info("EldoradoRobuxPriceSentryJob: no alert sent"); Log::info("EldoradoRobuxPriceSentryJob: no alert sent");
} }
} }
private function textToFloat(string $text): float
{
return floatval(str_replace(["", ","], ["", "."], trim($text)));
}
} }