|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace whm\Smoke\Extensions\SmokeReporter\Reporter; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
6
|
|
|
use whm\Smoke\Config\Configuration; |
|
7
|
|
|
use whm\Smoke\Extensions\SmokeResponseRetriever\Retriever\Retriever; |
|
8
|
|
|
use whm\Smoke\Rules\CheckResult; |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
class HtmlReporter implements Reporter |
|
12
|
|
|
{ |
|
13
|
|
|
private $results = []; |
|
14
|
|
|
/** |
|
15
|
|
|
* @var Configuration |
|
16
|
|
|
*/ |
|
17
|
|
|
private $templateDir; |
|
18
|
|
|
private $templateFile; |
|
19
|
|
|
private $resultFile; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var OutputInterface |
|
23
|
|
|
*/ |
|
24
|
|
|
private $output; |
|
25
|
|
|
|
|
26
|
|
|
public function init(OutputInterface $_output, $resultFile, $templateDir = null, $templateFile = 'index.html.twig') |
|
27
|
|
|
{ |
|
28
|
|
|
$this->resultFile = $resultFile; |
|
29
|
|
|
|
|
30
|
|
|
if ($templateDir === null) { |
|
31
|
|
|
$this->templateDir = __DIR__ . '/templates'; |
|
|
|
|
|
|
32
|
|
|
} else { |
|
33
|
|
|
$this->templateDir = $templateDir; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
$this->templateFile = $templateFile; |
|
37
|
|
|
$this->output = $_output; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @param CheckResult[] $results |
|
42
|
|
|
*/ |
|
43
|
|
|
public function processResults($results) |
|
44
|
|
|
{ |
|
45
|
|
|
foreach ($results as $result) { |
|
46
|
|
|
$this->results[] = [ |
|
47
|
|
|
'url' => $result->getResponse()->getUri(), |
|
48
|
|
|
'rule' => $result->getRuleName(), |
|
49
|
|
|
'message' => $result->getMessage(), |
|
50
|
|
|
'status' => $result->getStatus(), |
|
51
|
|
|
]; |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function finish() |
|
56
|
|
|
{ |
|
57
|
|
|
$loader = new \Twig_Loader_Filesystem($this->templateDir); |
|
|
|
|
|
|
58
|
|
|
$twig = new \Twig_Environment($loader); |
|
59
|
|
|
|
|
60
|
|
|
$html = $twig->render($this->templateFile, [ |
|
61
|
|
|
'results' => $this->results, |
|
62
|
|
|
]); |
|
63
|
|
|
|
|
64
|
|
|
if (!file_exists(dirname($this->resultFile))) { |
|
65
|
|
|
mkdir(dirname($this->resultFile)); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
if (!file_put_contents($this->resultFile, $html)) { |
|
69
|
|
|
$this->output->writeln("<error>HTML Reporter extension: Could not write result file to " . $this->resultFile ."</error>"); |
|
70
|
|
|
} else { |
|
71
|
|
|
$this->output->writeln("<info>HTML Reporter extension:</info> Result file written to " . $this->resultFile); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
} |
|
76
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..