taurus-api/src/App/Service/JcatInfoCollectorService.php

71 lines
1.6 KiB
PHP
Raw Normal View History

<?php
namespace App\Service;
use League\Csv\Reader;
use League\Csv\Statement;
use Zend\Config\Config;
use Zend\Http\Client;
class JcatInfoCollectorService
{
/**
* @var Config
*/
private $config;
/**
* @var Client
*/
private $httpClient;
/**
* JiraClientService constructor.
* @param Client $client
* @param Config $config
*/
public function __construct(Client $client, Config $config)
{
$this->httpClient = $client;
$this->config = $config;
}
public function getTrFlow()
{
/** @var Config $kanbanBoardUriParams */
$trFlowUri = $this->config->get('url.jcatTrFlow');
$response = $this->httpClient
->setUri($trFlowUri)
->send();
if (!$response->isSuccess()) {
throw new \UnexpectedValueException("Bad JCAT result", $response->getStatusCode());
}
return $this->parseFlowHtmlResult($response->getBody());
}
private function parseFlowHtmlResult(string $html)
{
$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 \DOMNodeList $elements */
$elements = $documentXpath->query('//tr/td[1]');
$result = [];
/** @var \DOMElement $element */
foreach ($elements as $element) {
$result[] = trim($element->nodeValue);
}
return array_count_values($result);
}
}