|
5 | 5 | use SensioLabs\DeprecationDetector\Console\Output\VerboseProgressOutput; |
6 | 6 | use SensioLabs\DeprecationDetector\FileInfo\PhpFileInfo; |
7 | 7 | use SensioLabs\DeprecationDetector\Parser\ParserInterface; |
8 | | -use Symfony\Component\Finder\Finder; |
| 8 | +use PhpParser\Error; |
9 | 9 |
|
10 | | -class ParsedPhpFileFinder extends Finder |
| 10 | +class ParsedPhpFileFinder |
11 | 11 | { |
12 | 12 | /** |
13 | 13 | * @var ParserInterface |
14 | 14 | */ |
15 | | - protected $parser; |
| 15 | + private $parser; |
16 | 16 |
|
17 | 17 | /** |
18 | 18 | * @var VerboseProgressOutput |
19 | 19 | */ |
20 | | - protected $progressOutput; |
| 20 | + private $progressOutput; |
21 | 21 |
|
22 | 22 | /** |
23 | | - * @var \PhpParser\Error[] |
| 23 | + * @var FinderFactoryInterface |
24 | 24 | */ |
25 | | - protected $parserErrors = array(); |
| 25 | + private $finderFactory; |
26 | 26 |
|
27 | 27 | /** |
28 | | - * @param ParserInterface $parser |
29 | | - * @param VerboseProgressOutput $progressOutput |
| 28 | + * @param ParserInterface $parser |
| 29 | + * @param VerboseProgressOutput $progressOutput |
| 30 | + * @param FinderFactoryInterface $finderFactory |
30 | 31 | */ |
31 | | - public function __construct(ParserInterface $parser, VerboseProgressOutput $progressOutput) |
| 32 | + public function __construct(ParserInterface $parser, VerboseProgressOutput $progressOutput, FinderFactoryInterface $finderFactory) |
32 | 33 | { |
33 | | - parent::__construct(); |
34 | | - |
35 | 34 | $this->parser = $parser; |
36 | | - $this->files()->name('*.php'); |
37 | | - |
38 | 35 | $this->progressOutput = $progressOutput; |
| 36 | + $this->finderFactory = $finderFactory; |
39 | 37 | } |
40 | 38 |
|
41 | 39 | /** |
42 | | - * @return \Iterator |
| 40 | + * @param string $path |
| 41 | + * |
| 42 | + * @return Result |
43 | 43 | */ |
44 | | - public function getIterator() |
| 44 | + public function parsePhpFiles($path) |
45 | 45 | { |
46 | | - $iterator = parent::getIterator(); |
47 | | - $files = new \ArrayIterator(); |
48 | | - $total = $this->count(); |
| 46 | + $files = $this->finderFactory->createFinder()->in($path); |
| 47 | + $parsedFiles = array(); |
| 48 | + $parserErrors = array(); |
49 | 49 |
|
50 | | - $this->progressOutput->start($total); |
| 50 | + $this->progressOutput->start($fileCount = $files->count()); |
51 | 51 |
|
52 | 52 | $i = 0; |
53 | | - foreach ($iterator as $file) { |
| 53 | + foreach ($files->getIterator() as $file) { |
54 | 54 | $file = PhpFileInfo::create($file); |
55 | 55 |
|
56 | 56 | try { |
57 | 57 | $this->progressOutput->advance(++$i, $file); |
58 | 58 | $this->parser->parseFile($file); |
59 | | - } catch (\PhpParser\Error $ex) { |
| 59 | + } catch (Error $ex) { |
60 | 60 | $raw = $ex->getRawMessage().' in file '.$file; |
61 | 61 | $ex->setRawMessage($raw); |
62 | | - $this->parserErrors[] = $ex; |
| 62 | + $parserErrors[] = $ex; |
63 | 63 | } |
64 | 64 |
|
65 | | - $files->append($file); |
| 65 | + $parsedFiles[] = $file; |
66 | 66 | } |
67 | 67 |
|
68 | 68 | $this->progressOutput->end(); |
69 | 69 |
|
70 | | - return $files; |
71 | | - } |
72 | | - |
73 | | - /** |
74 | | - * @return int |
75 | | - */ |
76 | | - public function count() |
77 | | - { |
78 | | - return iterator_count(parent::getIterator()); |
79 | | - } |
80 | | - |
81 | | - /** |
82 | | - * @return \PhpParser\Error[] |
83 | | - */ |
84 | | - public function getParserErrors() |
85 | | - { |
86 | | - return $this->parserErrors; |
87 | | - } |
88 | | - |
89 | | - /** |
90 | | - * @param ParserInterface $parser |
91 | | - * @param VerboseProgressOutput $progressOutput |
92 | | - * @return ParsedPhpFileFinder |
93 | | - */ |
94 | | - public static function deprecationFinder(ParserInterface $parser, VerboseProgressOutput $progressOutput) |
95 | | - { |
96 | | - $finder = new ParsedPhpFileFinder($parser, $progressOutput); |
97 | | - $finder |
98 | | - ->contains('@deprecated') |
99 | | - ->exclude('vendor') |
100 | | - ->exclude('Tests') |
101 | | - ->exclude('Test'); |
102 | | - |
103 | | - return $finder; |
104 | | - |
105 | | - } |
106 | | - |
107 | | - /** |
108 | | - * @param ParserInterface $parser |
109 | | - * @param VerboseProgressOutput $progressOutput |
110 | | - * @return ParsedPhpFileFinder |
111 | | - */ |
112 | | - public static function usageFinder(ParserInterface $parser, VerboseProgressOutput $progressOutput) |
113 | | - { |
114 | | - $finder = new ParsedPhpFileFinder($parser, $progressOutput); |
115 | | - $finder |
116 | | - ->exclude('vendor') |
117 | | - ->exclude('Tests') |
118 | | - ->exclude('Test'); |
119 | | - |
120 | | - return $finder; |
121 | | - } |
122 | | - |
123 | | - /** |
124 | | - * @return ParserInterface |
125 | | - */ |
126 | | - public function getParser() |
127 | | - { |
128 | | - return $this->parser; |
129 | | - } |
130 | | - |
131 | | - /** |
132 | | - * @return VerboseProgressOutput |
133 | | - */ |
134 | | - public function getOutput() |
135 | | - { |
136 | | - return $this->progressOutput; |
| 70 | + return new Result($parsedFiles, $parserErrors, $fileCount); |
137 | 71 | } |
138 | 72 | } |
0 commit comments