* account_id parsing simplified

* income category -> id replacement works now
This commit is contained in:
Danyi Dávid 2018-07-08 23:14:03 +02:00
parent 5d09d96cf2
commit b99d07627b

View File

@ -290,7 +290,6 @@ class KoinService
$body = $httpResponse->getBody();
$this->getCsrfToken($body);
$this->getAccountId($body);
$httpResponse = $this->httpClient
->post(self::BASE_URI . "/site/login", [
@ -307,9 +306,10 @@ class KoinService
/**
* @param $htmlData
*/
private function loadFormData($htmlData)
private function loadFormData(string $htmlData)
{
$documentXpath = $this->getCsrfToken($htmlData);
$this->getAccountId($documentXpath);
/** @var \DOMNodeList $expenseOptionElements */
$expenseOptionElements = $documentXpath->query('//select[@id="transaction-category_id"]/optgroup[@label="Kiadás"]/option');
@ -333,7 +333,7 @@ class KoinService
* @param $html
* @return \DOMXPath
*/
private function getCsrfToken($html): \DOMXPath
private function getCsrfToken(string $html): \DOMXPath
{
$xmlErrorHandling = libxml_use_internal_errors(TRUE);
$domDocument = new \DOMDocument();
@ -354,26 +354,14 @@ class KoinService
}
/**
* Parse account:id from html
*
* @param $html
* @return \DOMXPath
* Parse account_id from html
* @param \DOMXPath $documentXpath
*/
private function getAccountId($html): \DOMXPath
private function getAccountId(\DOMXPath $documentXpath)
{
$xmlErrorHandling = libxml_use_internal_errors(TRUE);
$domDocument = new \DOMDocument();
$domDocument->loadHTML($html);
libxml_clear_errors();
libxml_use_internal_errors($xmlErrorHandling);
$documentXpath = new \DOMXPath($domDocument);
/** @var \DOMElement $accountIdElement */
$accountIdElement = $documentXpath->query('//input[@id="transaction-account_id"]')->item(0);
$this->csrfParam = $accountIdElement->getAttribute("value");
return $documentXpath;
$this->accountId = $accountIdElement->getAttribute("value");
}
/**
@ -413,11 +401,16 @@ class KoinService
}
/**
* Returns the category id from the human readable name
* Income is scanned first, if there is a duplicate type it will be treated as income
* @param string $category
* @return string
*/
private function getCategoryId(string $category): string
{
if (in_array($category, array_keys($this->incomeCategories))) {
return $this->incomeCategories[$category];
}
if (in_array($category, array_keys($this->expenseCategories))) {
return $this->expenseCategories[$category];
}