|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* This file is part of project-quality-inspector. |
|
4
|
|
|
* |
|
5
|
|
|
* (c) Alexandre GESLIN <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace ProjectQualityInspector\Application\Output; |
|
12
|
|
|
|
|
13
|
|
|
use ProjectQualityInspector\Exception\RuleViolationException; |
|
14
|
|
|
use ProjectQualityInspector\Rule\RuleInterface; |
|
15
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
16
|
|
|
|
|
17
|
|
|
class UIHelper |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @param OutputInterface $output |
|
21
|
|
|
* @param string $configFile |
|
22
|
|
|
* @param string $version |
|
23
|
|
|
*/ |
|
24
|
|
|
public static function displayStartingBlock(OutputInterface $output, $configFile, $version) |
|
25
|
|
|
{ |
|
26
|
|
|
$output->writeln(sprintf('<question>Starting Project Quality Inspector v%s with config file "%s"</question>', $version, $configFile)); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @param RuleInterface $rule |
|
31
|
|
|
* @param OutputInterface $output |
|
32
|
|
|
*/ |
|
33
|
|
|
public static function displayRuleSuccess(RuleInterface $rule, OutputInterface $output) |
|
34
|
|
|
{ |
|
35
|
|
|
$output->writeln(sprintf('<info>%s: OK</info>', $rule::getRuleName())); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @param RuleViolationException $e |
|
40
|
|
|
* @param OutputInterface $output |
|
41
|
|
|
*/ |
|
42
|
|
|
public static function displayRuleViolation(RuleViolationException $e, OutputInterface $output) |
|
43
|
|
|
{ |
|
44
|
|
|
$rule = $e->getRule(); |
|
45
|
|
|
$output->writeln(sprintf('<error>%s: KO</error>', $rule::getRuleName())); |
|
46
|
|
|
|
|
47
|
|
|
foreach ($e->getExpectationFailedExceptions() as $expectationFailedException) { |
|
48
|
|
|
$reason = ($expectationFailedException->getReason()) ? sprintf(' Reason: %s', $expectationFailedException->getReason()): ''; |
|
49
|
|
|
$output->writeln(sprintf('<comment>Expectation failed: %s.%s</comment>', $expectationFailedException->getMessage(), $reason)); |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @param \Exception $e |
|
55
|
|
|
* @param OutputInterface $output |
|
56
|
|
|
*/ |
|
57
|
|
|
public static function displayException(\Exception $e, OutputInterface $output) |
|
58
|
|
|
{ |
|
59
|
|
|
$output->writeln(sprintf('<error>Error: %s : %s::%s</error>', $e->getMessage(), $e->getFile(), $e->getLine())); |
|
60
|
|
|
} |
|
61
|
|
|
} |