From 53015e176a6054a2729b32f3b8343958553d0ddc Mon Sep 17 00:00:00 2001 From: Richard Muvirimi Date: Sat, 3 Jun 2023 22:38:46 +0200 Subject: [PATCH] Update dependencies, update crawl status --- app/Entities/Rate.php | 42 +++++++++++++++++++++--------------------- composer.json | 10 +++++----- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/app/Entities/Rate.php b/app/Entities/Rate.php index 85d2764..78c2eaf 100644 --- a/app/Entities/Rate.php +++ b/app/Entities/Rate.php @@ -42,9 +42,9 @@ class Rate extends Entity * @var string[] */ protected $casts = [ - 'rate' => 'float', - 'enabled' => 'boolean', - 'status' => 'boolean', + 'rate' => 'float', + 'enabled' => 'boolean', + 'status' => 'boolean', 'javascript' => 'boolean', ]; @@ -54,9 +54,9 @@ class Rate extends Entity * @var string[] */ protected $datamap = [ - 'lastChecked' => 'last_checked', + 'lastChecked' => 'last_checked', 'lastUpdatedSelector' => 'last_updated_selector', - 'lastUpdated' => 'last_updated', + 'lastUpdated' => 'last_updated', ]; /** @@ -86,12 +86,12 @@ public function crawlSite(): void /** * Get site html file and scan for required fields */ - if (! $this->site) { + if (!$this->site) { $this->getHtmlContent(); } if ($this->site) { - $this->status = $this->parseHtml($this->site) === true ? 1 : 0; + $this->status = $this->parseHtml($this->site) === true; //last checked $this->lastChecked = Time::now(); @@ -138,7 +138,7 @@ private function parseHtml(string $html): bool $converter = new CssSelectorConverter(); $selector = $this->selector; - if (! $this->isXpath($selector)) { + if (!$this->isXpath($selector)) { $selector = $converter->toXPath($selector); } @@ -151,7 +151,7 @@ private function parseHtml(string $html): bool $this->rate = $rate; $lastUpdatedSelector = $this->lastUpdatedSelector; - if (! $this->isXpath($lastUpdatedSelector)) { + if (!$this->isXpath($lastUpdatedSelector)) { $lastUpdatedSelector = $converter->toXPath($lastUpdatedSelector); } @@ -188,7 +188,7 @@ private function fixDateOffset(Time $date): Time /** * Convert number to an int * - * @param string $value Rate. + * @param string $value Rate. * @param string $locale Locale to parse number * * @return float @@ -200,7 +200,7 @@ private function cleanRate(string $value, string $locale): float { $amount = $this->clean($value); - if (! is_numeric($amount)) { + if (!is_numeric($amount)) { $words = explode(' ', $amount); //remove non-numeric words @@ -213,7 +213,7 @@ private function cleanRate(string $value, string $locale): float //join to allow removing non-numeric characters $numbers = implode(' ', $numbered); - $fmt = new NumberFormatter($locale, NumberFormatter::DECIMAL); + $fmt = new NumberFormatter($locale, NumberFormatter::DECIMAL); $numbers = $fmt->parse($numbers); //split by non-numeric @@ -300,7 +300,7 @@ private function cleanDate(string $value): Time /** * Return parsed date substituting with defaults on none existent parts */ - // phpcs:ignore Generic.Files.LineLength.TooLong + // phpcs:ignore Generic.Files.LineLength.TooLong return Time::create($date['year'] ?: date('Y'), $date['month'] ?: date('n'), $date['day'] ?: date('j'), $date['hour'] ?: 0, $date['minute'] ?: 0, $date['second'] ?: 0); } @@ -340,19 +340,19 @@ public function getHtmlContent(): void $client = Services::curlrequest(); $data = [ - 'url' => $this->url, - 'format' => 'html', - 'timeout' => getenv('scrappy.timeout'), + 'url' => $this->url, + 'format' => 'html', + 'timeout' => getenv('scrappy.timeout'), 'user_agent' => $this->getUserAgent(), - 'css' => 'body', + 'css' => 'body', ]; try { $response = $client->post(getenv('scrappy.server') . '/scrape', [ 'user_agent' => $this->getUserAgent(), - 'multipart' => $data, - 'verify' => false, - 'headers' => [ + 'multipart' => $data, + 'verify' => false, + 'headers' => [ 'Authorization' => 'Bearer ' . getenv('scrappy.authKey'), ], ]); @@ -383,7 +383,7 @@ private function getUserAgent(): string { $agent = cache('user-agent'); - if (! $agent) { + if (!$agent) { $agent = getenv("USER_AGENT"); $agent = preg_replace('/headless/i', '', $agent); diff --git a/composer.json b/composer.json index 4203e4e..29980ce 100755 --- a/composer.json +++ b/composer.json @@ -26,22 +26,22 @@ "php": ">=8.1", "codeigniter4/framework": "^4.3", "symfony/polyfill-php82": "^1.27", - "webonyx/graphql-php": "^15.4", + "webonyx/graphql-php": "^15.5", "ext-json": "*", "ext-intl": "*", - "symfony/dom-crawler": "^6.2", - "symfony/css-selector": "^6.2", + "symfony/dom-crawler": "^6.3", + "symfony/css-selector": "^6.3", "br33f/php-ga4-mp": "^0.1.3" }, "require-dev": { - "fakerphp/faker": "^1.21", + "fakerphp/faker": "^1.22", "mikey179/vfsstream": "^1.6", "phpunit/phpunit": "^9.6", "squizlabs/php_codesniffer": "^3.7", "phpcompatibility/php-compatibility": "^9.3", "dealerdirect/phpcodesniffer-composer-installer": "^1.0", "inpsyde/composer-assets-compiler": "^3.0", - "friendsofphp/php-cs-fixer": "^3.16" + "friendsofphp/php-cs-fixer": "^3.17" }, "suggest": { "ext-fileinfo": "Improves mime type detection for files"