1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* (c) Jean-François Lépine <https://twitter.com/Halleck45> |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Hal\Application\Formater\Summary; |
11
|
|
|
use Hal\Application\Formater\FormaterInterface; |
12
|
|
|
use Hal\Application\Rule\Validator; |
13
|
|
|
use Hal\Component\Bounds\BoundsInterface; |
14
|
|
|
use Hal\Component\Result\ResultCollection; |
15
|
|
|
use Symfony\Component\Console\Output\ConsoleOutput; |
16
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
17
|
|
|
use Hal\Application\Score\Scoring; |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Formater for cli usage |
22
|
|
|
* |
23
|
|
|
* @author Jean-François Lépine <https://twitter.com/Halleck45> |
24
|
|
|
*/ |
25
|
|
|
class Cli implements FormaterInterface { |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Validator |
29
|
|
|
* |
30
|
|
|
* @var \Hal\Application\Rule\Validator |
31
|
|
|
*/ |
32
|
|
|
private $validator; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Bounds |
36
|
|
|
* |
37
|
|
|
* @var BoundsInterface |
38
|
|
|
*/ |
39
|
|
|
private $bound; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var OutputInterface |
43
|
|
|
*/ |
44
|
|
|
private $output; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Constructor |
48
|
|
|
* |
49
|
|
|
* @param Validator $validator |
50
|
|
|
* @param BoundsInterface $bound |
51
|
|
|
* @param OutputInterface $output |
52
|
|
|
*/ |
53
|
|
|
public function __construct(Validator $validator, BoundsInterface $bound, OutputInterface $output) |
54
|
|
|
{ |
55
|
|
|
$this->bound = $bound; |
56
|
|
|
$this->validator = $validator; |
57
|
|
|
$this->output = $output; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @inheritdoc |
62
|
|
|
*/ |
63
|
|
|
public function terminate(ResultCollection $collection, ResultCollection $groupedResults){ |
64
|
|
|
|
65
|
|
|
$this->output->write(str_pad("\x0D", 80, "\x20")); |
66
|
|
|
$this->output->writeln(''); |
67
|
|
|
|
68
|
|
|
// score |
69
|
|
|
$score = $collection->getScore(); |
70
|
|
|
// if($score) { |
71
|
|
|
foreach ($score->all() as $name => $value) { |
72
|
|
|
$this->output->writeln(sprintf('%s %s', str_pad($name, 35, '.'), str_pad($value, 5, ' ', STR_PAD_LEFT). ' / ' . Scoring::MAX)); |
73
|
|
|
} |
74
|
|
|
$this->output->writeln(''); |
75
|
|
|
// } |
76
|
|
|
|
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @inheritdoc |
81
|
|
|
*/ |
82
|
|
|
public function getName() { |
83
|
|
|
return 'Summary CLI'; |
84
|
|
|
} |
85
|
|
|
} |