diff --git a/app/Check/Consumers/XpathCheck.php b/app/Check/Consumers/XpathCheck.php index f45f7d3..9a20aa4 100644 --- a/app/Check/Consumers/XpathCheck.php +++ b/app/Check/Consumers/XpathCheck.php @@ -11,23 +11,17 @@ final class XpathCheck extends Check /** - * @param \Pd\Monitoring\Check\Check|\Pd\Monitoring\Check\XpathCheck $check + * @param \Pd\Monitoring\Check\XpathCheck $check * @return bool */ protected function doHardJob(\Pd\Monitoring\Check\Check $check): bool { $check->xpathLastResult = NULL; - $client = new \GuzzleHttp\Client(); - - $options = [ - 'connect_timeout' => $check::ALIVE_TIMEOUT / 1000, - 'timeout' => 2 * $check::ALIVE_TIMEOUT / 1000, - 'headers' => [ - 'User-Agent' => 'PeckaMonitoringBot/1.0', - ], - 'allow_redirects' => TRUE, - ]; + $guzzleOptions = \Pd\Monitoring\Check\Consumers\Client\Configuration::create($check::ALIVE_TIMEOUT / 1000, 2 * (\round($check::ALIVE_TIMEOUT / 1000))) + ->withAllowRedirects(\Pd\Monitoring\Check\Consumers\Client\Configuration\AllowRedirects::create(TRUE)) + ; + $client = new \GuzzleHttp\Client($guzzleOptions->config()); if ($check->siteMap && ! $this->siteMapLoader) { $this->siteMapLoader = new \Pd\Monitoring\Check\SiteMapLoader($check->url); @@ -37,7 +31,7 @@ protected function doHardJob(\Pd\Monitoring\Check\Check $check): bool if ($this->siteMapLoader) { $withoutError = TRUE; while ($url = $this->siteMapLoader->getNextUrl($this->lastUrl)) { - $loaded = $this->loadUrl($client, $options, $check, $url); + $loaded = $this->loadUrl($client, $check, $url); if ( ! $loaded) { $this->logError($check, \sprintf('Došlo k chybě na url "%s"', $url)); $withoutError = FALSE; @@ -47,7 +41,7 @@ protected function doHardJob(\Pd\Monitoring\Check\Check $check): bool return $withoutError; } else { - $loaded = $this->loadUrl($client, $options, $check, $check->url); + $loaded = $this->loadUrl($client, $check, $check->url); if ($loaded) { return TRUE; } @@ -67,9 +61,9 @@ protected function getCheckType(): int } - private function loadUrl(\GuzzleHttp\Client $client, array $options, \Pd\Monitoring\Check\XpathCheck $check, string $url): bool + private function loadUrl(\GuzzleHttp\Client $client, \Pd\Monitoring\Check\XpathCheck $check, string $url): bool { - $response = $client->request('GET', $url, $options); + $response = $client->get($url); if ($response->getStatusCode() !== 200) { $this->logHeaders($check, $response); diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index e1b02cb..50e0e1b 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -470,11 +470,6 @@ parameters: count: 1 path: app/Check/Consumers/XpathCheck.php - - - message: "#^Method Pd\\\\Monitoring\\\\Check\\\\Consumers\\\\XpathCheck\\:\\:loadUrl\\(\\) has parameter \\$options with no value type specified in iterable type array\\.$#" - count: 1 - path: app/Check/Consumers/XpathCheck.php - - message: "#^Only booleans are allowed in a negated boolean, Pd\\\\Monitoring\\\\Check\\\\SiteMapLoader\\|null given\\.$#" count: 1 @@ -485,11 +480,6 @@ parameters: count: 1 path: app/Check/Consumers/XpathCheck.php - - - message: "#^Parameter \\#3 \\$check of method Pd\\\\Monitoring\\\\Check\\\\Consumers\\\\XpathCheck\\:\\:loadUrl\\(\\) expects Pd\\\\Monitoring\\\\Check\\\\XpathCheck, Pd\\\\Monitoring\\\\Check\\\\Check given\\.$#" - count: 2 - path: app/Check/Consumers/XpathCheck.php - - message: "#^Only booleans are allowed in &&, string\\|null given on the left side\\.$#" count: 1