88 lines
2.3 KiB
PHP
88 lines
2.3 KiB
PHP
<?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 getTrFlowErrors()
|
|
{
|
|
/** @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());
|
|
}
|
|
|
|
/**
|
|
* @param string $html
|
|
* @return array
|
|
*/
|
|
private function parseFlowHtmlResult(string $html)
|
|
{
|
|
$teamMembers = $this->config->get('team.members')->toArray();
|
|
$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) {
|
|
/** @var \DOMNodeList $ownerElements */
|
|
$ownerElements = $documentXpath->query('./td[6]', $element->parentNode);
|
|
$owner = strtolower(trim($ownerElements->item(0)->nodeValue));
|
|
if (in_array($owner, $teamMembers)) {
|
|
$result[] = trim($element->nodeValue);
|
|
}
|
|
}
|
|
|
|
$errorsCounted = array_count_values($result);
|
|
|
|
return array_map(function($type, $count) {
|
|
return [
|
|
'label' => $type,
|
|
'value' => $count,
|
|
];
|
|
}, array_keys($errorsCounted), $errorsCounted);
|
|
}
|
|
}
|