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

Commit 73d36da

Browse files
authored
Merge branch 'master' into feature/php-parser-3x
2 parents 978c1b1 + 0cd7869 commit 73d36da

File tree

15 files changed

+222
-62
lines changed

15 files changed

+222
-62
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ You can get a list of all options and arguments by running
9797
$ deprecation-detector check --help
9898
```
9999

100+
The default output might not fit into the cli. If that is the case you can set the output to a list by setting `--output=simple`.
101+
102+
```bash
103+
$ deprecation-detector check src/ vendor/ --output=simple
104+
```
105+
100106
## Excluding deprecated method calls
101107

102108
You can exclude deprecated method calls by using the `filter-methods` option. This option takes a comma separated list of method references to exclude.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
],
1616
"require": {
1717
"php": ">=5.5.9 || ^7.0",
18-
"nikic/php-parser": "3.*",
18+
"nikic/php-parser": "~3.0",
1919
"symfony/console": "^2.6 || ^3.0",
2020
"symfony/finder": "^2.6 || ^3.0",
2121
"phpdocumentor/reflection-docblock": "~2.0",

src/Configuration/Configuration.php

Lines changed: 17 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,12 @@ public function logHtml()
138146
{
139147
return $this->logHtml;
140148
}
149+
150+
/**
151+
* @return bool
152+
*/
153+
public function isSimpleOutput()
154+
{
155+
return $this->output === 'simple';
156+
}
141157
}

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
/**

src/FileInfo/PhpFileInfo.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ public function hasClassDeprecation($className)
280280
*/
281281
public function getClassDeprecation($className)
282282
{
283-
return ($this->hasClassDeprecation($className) ? $this->classDeprecations[$className] : null);
283+
return $this->hasClassDeprecation($className) ? $this->classDeprecations[$className] : null;
284284
}
285285

286286
/**
@@ -324,7 +324,7 @@ public function hasInterfaceDeprecation($interfaceName)
324324
*/
325325
public function getInterfaceDeprecation($interfaceName)
326326
{
327-
return ($this->hasInterfaceDeprecation($interfaceName) ? $this->interfaceDeprecations[$interfaceName] : null);
327+
return $this->hasInterfaceDeprecation($interfaceName) ? $this->interfaceDeprecations[$interfaceName] : null;
328328
}
329329

330330
/**

src/RuleSet/Loader/Composer/Package.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public static function fromArray(array $package)
4242
*/
4343
public function generatePackageKey()
4444
{
45-
return str_replace('/', '_', $this->name).'_'.$this->version;
45+
return str_replace(array('/', '\\', ':'), '_', $this->name).'_'.$this->version;
4646
}
4747

4848
/**

src/RuleSet/Loader/DirectoryLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,6 @@ public function loadRuleSet($path)
5656
*/
5757
private function generateDirectoryKey($path)
5858
{
59-
return str_replace('/', '_', $path);
59+
return str_replace(array('/', '\\', ':'), '_', $path);
6060
}
6161
}

src/TypeGuessing/SymbolTable/Resolver/SymfonyResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,6 @@ protected function getType($context, $methodName, Node $node = null)
121121
*/
122122
protected function isController($type)
123123
{
124-
return (substr($type, -10) === 'Controller');
124+
return substr($type, -10) === 'Controller';
125125
}
126126
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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+
33+
/**
34+
* @param Violation[] $violations
35+
* @param Error[] $errors
36+
*/
37+
public function renderViolations(array $violations, array $errors)
38+
{
39+
$this->printViolations($violations);
40+
$this->printErrors($errors);
41+
}
42+
43+
/**
44+
* @param Violation[] $violations
45+
*/
46+
abstract protected function printViolations(array $violations);
47+
48+
/**
49+
* @param Error[] $errors
50+
*/
51+
protected function printErrors(array $errors)
52+
{
53+
if (0 === count($errors)) {
54+
return;
55+
}
56+
57+
$this->output->writeln('');
58+
$this->output->writeln('<error>Your project contains invalid code:</error>');
59+
foreach ($errors as $error) {
60+
$this->output->writeln(
61+
sprintf(
62+
'<error>%s</error>',
63+
$error->getRawMessage()
64+
)
65+
);
66+
}
67+
}
68+
}

0 commit comments

Comments
 (0)