|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace DependencyAnalyzer\Commands; |
|
5
|
|
|
|
|
6
|
|
|
use DependencyAnalyzer\DependencyDumper\ObserverInterface; |
|
7
|
|
|
use DependencyAnalyzer\Exceptions\AnalysedFileException; |
|
8
|
|
|
use DependencyAnalyzer\Exceptions\ResolveDependencyException; |
|
9
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
10
|
|
|
|
|
11
|
|
|
class DependencyDumperObserver implements ObserverInterface |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @var OutputInterface |
|
15
|
|
|
*/ |
|
16
|
|
|
private $output; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @var int |
|
20
|
|
|
*/ |
|
21
|
|
|
private $max = 0; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var int |
|
25
|
|
|
*/ |
|
26
|
|
|
private $counter = 0; |
|
27
|
|
|
|
|
28
|
|
|
public function __construct(OutputInterface $output) |
|
29
|
|
|
{ |
|
30
|
|
|
$this->output = $output; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function start(int $max): void |
|
34
|
|
|
{ |
|
35
|
|
|
$this->counter = 0; |
|
36
|
|
|
$this->max = $max; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function end(): void |
|
40
|
|
|
{ |
|
41
|
|
|
return; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function update(string $currentFile) |
|
45
|
|
|
{ |
|
46
|
|
|
$this->counter++; |
|
47
|
|
|
|
|
48
|
|
|
$this->output->writeln("Analyse start({$this->counter}/{$this->max}): {$currentFile}"); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function notifyAnalyzeFileError(AnalysedFileException $e) |
|
52
|
|
|
{ |
|
53
|
|
|
$this->output->writeln("Error: analysing file is failed. file is {$e->getAnalysedFile()}."); |
|
54
|
|
|
|
|
55
|
|
|
if ($this->output->isVerbose()) { |
|
56
|
|
|
$this->output->writeln("exception: {$e->getMessage()} at {$e->getFile()}:{$e->getLine()}"); |
|
57
|
|
|
} |
|
58
|
|
|
if ($this->output->isVeryVerbose()) { |
|
59
|
|
|
$this->output->writeln("detail of exception: {$e}"); |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function notifyResolveDependencyError(string $file, ResolveDependencyException $e) |
|
64
|
|
|
{ |
|
65
|
|
|
$this->output->writeln("Error: resolving dependency is failed, node_type:{$e->getNodeType()} in {$file}:{$e->getNodeLine()}"); |
|
66
|
|
|
$this->output->writeln('Skip analysing this file, therefore result of analyse of this file is incomplete.'); |
|
67
|
|
|
|
|
68
|
|
|
if ($this->output->isVerbose()) { |
|
69
|
|
|
$this->output->writeln("exception: {$e->getMessage()} at {$e->getFile()}:{$e->getLine()}"); |
|
70
|
|
|
} |
|
71
|
|
|
if ($this->output->isVeryVerbose()) { |
|
72
|
|
|
$this->output->writeln("detail of exception: {$e}"); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|