Skip to content
This repository was archived by the owner on May 6, 2025. It is now read-only.

Commit af0ca73

Browse files
committed
Simple Console output
1 parent 7707685 commit af0ca73

File tree

7 files changed

+137
-22
lines changed

7 files changed

+137
-22
lines changed

src/Configuration/Configuration.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ class Configuration
4444
*/
4545
private $logHtml;
4646

47+
/**
48+
* @var string
49+
*/
50+
private $output;
51+
4752
/**
4853
* @param string $ruleSet
4954
* @param string $containerPath
@@ -53,6 +58,7 @@ class Configuration
5358
* @param bool $fail
5459
* @param bool $verbose
5560
* @param string $logHtml
61+
* @param string $output
5662
*/
5763
public function __construct(
5864
$ruleSet,
@@ -62,7 +68,8 @@ public function __construct(
6268
$filterMethodCalls,
6369
$fail,
6470
$verbose,
65-
$logHtml)
71+
$logHtml,
72+
$output)
6673
{
6774
$this->ruleSet = $ruleSet;
6875
$this->containerPath = $containerPath;
@@ -72,6 +79,7 @@ public function __construct(
7279
$this->failOnDeprecation = $fail;
7380
$this->verbose = $verbose;
7481
$this->logHtml = $logHtml;
82+
$this->output = $output;
7583
}
7684

7785
public function overrideConfiguration()
@@ -138,4 +146,11 @@ public function logHtml()
138146
{
139147
return $this->logHtml;
140148
}
149+
150+
/**
151+
* @return bool
152+
*/
153+
public function isSimpleOutput() {
154+
return $this->output === 'simple';
155+
}
141156
}

src/Console/Command/CheckCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ protected function configure()
3838
new InputOption('no-cache', null, InputOption::VALUE_NONE, 'Disable rule set cache'),
3939
new InputOption('cache-dir', null, InputOption::VALUE_REQUIRED, 'Cache directory', '.rules/'),
4040
new InputOption('log-html', null, InputOption::VALUE_REQUIRED, 'Generate HTML report'),
41+
new InputOption('output', null, InputOption::VALUE_REQUIRED, 'Change the output mode'),
4142
new InputOption('filter-methods', null, InputOption::VALUE_OPTIONAL, 'Filter methods', ''),
4243
new InputOption('fail', null, InputOption::VALUE_NONE, 'Fails, if any deprecation is detected'),
4344
)
@@ -113,7 +114,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
113114
$input->getOption('filter-methods'),
114115
$input->getOption('fail'),
115116
$input->getOption('verbose'),
116-
$input->getOption('log-html')
117+
$input->getOption('log-html'),
118+
$input->getOption('output')
117119
);
118120

119121
$factory = new DetectorFactory();

src/DetectorFactory.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
use SensioLabs\DeprecationDetector\TypeGuessing\SymbolTable\SymbolTable;
3636
use SensioLabs\DeprecationDetector\TypeGuessing\SymbolTable\Visitor\SymbolTableVariableResolverVisitor;
3737
use SensioLabs\DeprecationDetector\TypeGuessing\Symfony\ContainerReader;
38-
use SensioLabs\DeprecationDetector\Violation\Renderer\ConsoleOutputRenderer;
38+
use SensioLabs\DeprecationDetector\Violation\Renderer\Console\DefaultRenderer;
3939
use SensioLabs\DeprecationDetector\Violation\Renderer\Html\RendererFactory;
4040
use SensioLabs\DeprecationDetector\Violation\Renderer\MessageHelper\Message\ClassViolationMessage;
4141
use SensioLabs\DeprecationDetector\Violation\Renderer\MessageHelper\Message\FunctionViolationMessage;
@@ -45,6 +45,7 @@
4545
use SensioLabs\DeprecationDetector\Violation\Renderer\MessageHelper\Message\MethodViolationMessage;
4646
use SensioLabs\DeprecationDetector\Violation\Renderer\MessageHelper\Message\SuperTypeViolationMessage;
4747
use SensioLabs\DeprecationDetector\Violation\Renderer\MessageHelper\MessageHelper;
48+
use SensioLabs\DeprecationDetector\Violation\Renderer\Console\SimpleRenderer;
4849
use SensioLabs\DeprecationDetector\Violation\ViolationChecker\ClassViolationChecker;
4950
use SensioLabs\DeprecationDetector\Violation\ViolationChecker\ComposedViolationChecker;
5051
use SensioLabs\DeprecationDetector\Violation\ViolationChecker\FunctionViolationChecker;
@@ -293,7 +294,7 @@ private function getViolationFilter(Configuration $configuration)
293294
* @param Configuration $configuration
294295
* @param OutputInterface $output
295296
*
296-
* @return ConsoleOutputRenderer|Violation\Renderer\Html\Renderer
297+
* @return DefaultRenderer|Violation\Renderer\Html\Renderer
297298
*/
298299
private function getRenderer(Configuration $configuration, OutputInterface $output)
299300
{
@@ -305,7 +306,11 @@ private function getRenderer(Configuration $configuration, OutputInterface $outp
305306
return $factory->createHtmlOutputRenderer($logFilePath);
306307
}
307308

308-
return new ConsoleOutputRenderer($output, $messageHelper);
309+
if ($configuration->isSimpleOutput()) {
310+
return new SimpleRenderer($output, $messageHelper);
311+
}
312+
313+
return new DefaultRenderer($output, $messageHelper);
309314
}
310315

311316
/**
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace SensioLabs\DeprecationDetector\Violation\Renderer\Console;
4+
5+
use PhpParser\Error;
6+
use SensioLabs\DeprecationDetector\Violation\Renderer\MessageHelper\MessageHelper;
7+
use SensioLabs\DeprecationDetector\Violation\Renderer\RendererInterface;
8+
use SensioLabs\DeprecationDetector\Violation\Violation;
9+
use Symfony\Component\Console\Output\OutputInterface;
10+
11+
abstract class BaseRenderer implements RendererInterface
12+
{
13+
/**
14+
* @var OutputInterface
15+
*/
16+
protected $output;
17+
18+
/**
19+
* @var MessageHelper
20+
*/
21+
protected $messageHelper;
22+
23+
/**
24+
* @param OutputInterface $output
25+
* @param MessageHelper $messageHelper
26+
*/
27+
public function __construct(OutputInterface $output, MessageHelper $messageHelper)
28+
{
29+
$this->output = $output;
30+
$this->messageHelper = $messageHelper;
31+
}
32+
}

src/Violation/Renderer/ConsoleOutputRenderer.php renamed to src/Violation/Renderer/Console/DefaultRenderer.php

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace SensioLabs\DeprecationDetector\Violation\Renderer;
3+
namespace SensioLabs\DeprecationDetector\Violation\Renderer\Console;
44

55
use PhpParser\Error;
66
use SensioLabs\DeprecationDetector\FileInfo\PhpFileInfo;
@@ -11,26 +11,15 @@
1111
use Symfony\Component\Console\Helper\TableSeparator;
1212
use Symfony\Component\Console\Output\OutputInterface;
1313

14-
class ConsoleOutputRenderer implements RendererInterface
14+
class DefaultRenderer extends BaseRenderer
1515
{
16-
/**
17-
* @var OutputInterface
18-
*/
19-
protected $output;
20-
21-
/**
22-
* @var MessageHelper
23-
*/
24-
private $messageHelper;
25-
2616
/**
2717
* @param OutputInterface $output
2818
* @param MessageHelper $messageHelper
2919
*/
3020
public function __construct(OutputInterface $output, MessageHelper $messageHelper)
3121
{
32-
$this->output = $output;
33-
$this->messageHelper = $messageHelper;
22+
parent::__construct($output, $messageHelper);
3423
}
3524

3625
/**
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
namespace SensioLabs\DeprecationDetector\Violation\Renderer\Console;
4+
5+
use PhpParser\Error;
6+
use SensioLabs\DeprecationDetector\Violation\Renderer\MessageHelper\MessageHelper;
7+
use SensioLabs\DeprecationDetector\Violation\Violation;
8+
use Symfony\Component\Console\Output\OutputInterface;
9+
10+
class SimpleRenderer extends BaseRenderer
11+
{
12+
/**
13+
* @param OutputInterface $output
14+
* @param MessageHelper $messageHelper
15+
*/
16+
public function __construct(OutputInterface $output, MessageHelper $messageHelper)
17+
{
18+
parent::__construct($output, $messageHelper);
19+
}
20+
21+
/**
22+
* @param Violation[] $violations
23+
* @param Error[] $errors
24+
*/
25+
public function renderViolations(array $violations, array $errors)
26+
{
27+
$this->printViolations($violations);
28+
$this->printErrors($errors);
29+
}
30+
31+
/**
32+
* @param Violation[] $violations
33+
*/
34+
private function printViolations(array $violations)
35+
{
36+
if (0 === count($violations)) {
37+
return;
38+
}
39+
40+
$tmpFile = null;
41+
foreach ($violations as $i => $violation) {
42+
if ($tmpFile !== $violation->getFile()) {
43+
$tmpFile = $violation->getFile();
44+
if (0 !== $i) {
45+
$this->output->writeln("");
46+
}
47+
$this->output->writeln($tmpFile->getRelativePathname());
48+
}
49+
50+
$this->output->writeln(sprintf(
51+
"Nr. %d line %d: %s",
52+
++$i,
53+
$violation->getLine(),
54+
$this->messageHelper->getViolationMessage($violation)
55+
));
56+
}
57+
}
58+
59+
/**
60+
* @param Error[] $errors
61+
*/
62+
private function printErrors(array $errors)
63+
{
64+
if (0 === count($errors)) {
65+
return;
66+
}
67+
68+
}
69+
}

tests/Configuration/ConfigurationTest.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ public function testClassIsInitializable()
1616
'',
1717
true,
1818
true,
19-
'html.log'
19+
'html.log',
20+
null
2021
);
2122

2223
$this->assertInstanceOf('SensioLabs\DeprecationDetector\Configuration\Configuration', $configuration);
2324
}
2425

25-
public function testRuleSet()
26+
public function testConfiguration()
2627
{
2728
$configuration = new Configuration(
2829
'path/to/rule_set',
@@ -32,7 +33,8 @@ public function testRuleSet()
3233
'',
3334
true,
3435
true,
35-
'html.log'
36+
'html.log',
37+
null
3638
);
3739

3840
$this->assertEquals('path/to/rule_set', $configuration->ruleSet());
@@ -43,5 +45,6 @@ public function testRuleSet()
4345
$this->assertTrue($configuration->failOnDeprecation());
4446
$this->assertTrue($configuration->isVerbose());
4547
$this->assertEquals('html.log', $configuration->logHtml());
48+
$this->assertNull(null, $configuration->isSimpleOutput());
4649
}
4750
}

0 commit comments

Comments
 (0)