notifyResolvePhpDocError()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 3
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace DependencyAnalyzer\Commands;
5
6
use DependencyAnalyzer\DependencyDumper\ObserverInterface;
7
use DependencyAnalyzer\DependencyGraph\FullyQualifiedStructuralElementName;
8
use DependencyAnalyzer\Exceptions\AnalyzedFileException;
9
use DependencyAnalyzer\Exceptions\InvalidFullyQualifiedStructureElementNameException;
10
use DependencyAnalyzer\Exceptions\ResolveDependencyException;
11
use Symfony\Component\Console\Output\OutputInterface;
12
13
class DependencyDumperObserver implements ObserverInterface
14
{
15
    /**
16
     * @var OutputInterface
17
     */
18
    private $output;
19
20
    /**
21
     * @var int
22
     */
23
    private $max = 0;
24
25
    /**
26
     * @var int
27
     */
28
    private $counter = 0;
29
30
    public function __construct(OutputInterface $output)
31
    {
32
        $this->output = $output;
33
    }
34
35
    public function start(int $max): void
36
    {
37
        $this->counter = 0;
38
        $this->max = $max;
39
    }
40
41
    public function end(): void
42
    {
43
        return;
44
    }
45
46
    public function update(string $currentFile): void
47
    {
48
        $this->counter++;
49
50
        $this->output->writeln("Analyze start({$this->counter}/{$this->max}): {$currentFile}");
51
    }
52
53
    public function notifyAnalyzeFileError(AnalyzedFileException $e): void
54
    {
55
        $this->output->writeln("Error: analyzing file is failed. file is {$e->getAnalyzedFile()}.");
56
57
        if ($this->output->isVerbose()) {
58
            $this->output->writeln("exception: {$e->getMessage()} at {$e->getFile()}:{$e->getLine()}");
59
        }
60
        if ($this->output->isVeryVerbose()) {
61
            $this->output->writeln("detail of exception: {$e}");
62
        }
63
    }
64
65
    public function notifyResolveDependencyError(string $file, ResolveDependencyException $e): void
66
    {
67
        $this->output->writeln("Error: resolving dependency is failed, node_type:{$e->getNodeType()} in {$file}:{$e->getNodeLine()}");
68
        $this->output->writeln('Skip analyzing this file, therefore result of analyze of this file is incomplete.');
69
70
        if ($this->output->isVerbose()) {
71
            $this->output->writeln("exception: {$e->getMessage()} at {$e->getFile()}:{$e->getLine()}");
72
        }
73
        if ($this->output->isVeryVerbose()) {
74
            $this->output->writeln("detail of exception: {$e}");
75
        }
76
    }
77
78
    public function notifyResolvePhpDocError(string $file, string $fqsen, InvalidFullyQualifiedStructureElementNameException $e): void
79
    {
80
        $this->output->writeln("Error: resolving phpdoc is failed, {$fqsen} in {$file}. Because element name is invalid: {$e->getInvalidElementName()}");
81
        $this->output->writeln('Skip analyzing this phpdoc, therefore result of analyze of this file is incomplete.');
82
    }
83
}
84