Skip to content

Commit

Permalink
#184 - the Configuration object is used – XpathCheck
Browse files Browse the repository at this point in the history
  • Loading branch information
AloisJasa committed Apr 12, 2023
1 parent 2be67fa commit ce42f26
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 25 deletions.
24 changes: 9 additions & 15 deletions app/Check/Consumers/XpathCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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;
}
Expand All @@ -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);
Expand Down
10 changes: 0 additions & 10 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit ce42f26

Please sign in to comment.