1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use PhUml\Parser\TokenParser; |
4
|
|
|
use PhUml\Processors\InvalidInitialProcessor; |
5
|
|
|
use PhUml\Processors\InvalidProcessorChain; |
6
|
|
|
|
7
|
|
|
class plPhuml |
8
|
|
|
{ |
9
|
|
|
/** @var TokenParser */ |
10
|
|
|
public $generator; |
11
|
|
|
|
12
|
|
|
/** @var string[] */ |
13
|
|
|
private $files; |
14
|
|
|
|
15
|
|
|
/** @var plProcessor[] */ |
16
|
|
|
private $processors; |
17
|
|
|
|
18
|
18 |
|
public function __construct() |
19
|
|
|
{ |
20
|
18 |
|
$this->generator = new TokenParser(); |
21
|
18 |
|
$this->processors = []; |
22
|
18 |
|
$this->files = []; |
23
|
18 |
|
} |
24
|
|
|
|
25
|
|
|
public function addDirectory(string $directory, string $extension = 'php', bool $recursive = true) |
26
|
|
|
{ |
27
|
|
|
if (!$recursive) { |
28
|
|
|
$iterator = new DirectoryIterator($directory); |
29
|
|
|
} else { |
30
|
|
|
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)); |
|
|
|
|
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
foreach ($iterator as $entry) { |
34
|
|
|
if (!$entry->isDir() && $entry->getExtension() === $extension) { |
35
|
|
|
$this->files[] = $entry->getPathname(); |
36
|
|
|
} |
37
|
|
|
} |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @throws InvalidInitialProcessor |
42
|
|
|
* @throws InvalidProcessorChain |
43
|
|
|
*/ |
44
|
18 |
|
public function addProcessor(plProcessor $processor): void |
45
|
|
|
{ |
46
|
18 |
|
if (count($this->processors) === 0 && !$processor->isInitial()) { |
47
|
6 |
|
throw InvalidInitialProcessor::given($processor); |
48
|
|
|
} |
49
|
12 |
|
$lastProcessor = end($this->processors); |
50
|
12 |
|
if (count($this->processors) > 0 && !$lastProcessor->isCompatibleWith($processor)) { |
51
|
12 |
|
throw InvalidProcessorChain::with($lastProcessor, $processor); |
52
|
|
|
} |
53
|
12 |
|
$this->processors[] = $processor; |
54
|
12 |
|
} |
55
|
|
|
|
56
|
|
|
public function generate($outfile) |
57
|
|
|
{ |
58
|
|
|
echo "[|] Parsing class structure\n"; |
59
|
|
|
$structure = $this->generator->createStructure($this->files); |
60
|
|
|
|
61
|
|
|
$input = $structure; |
62
|
|
|
foreach ($this->processors as $processor) { |
63
|
|
|
echo "[|] Running '{$processor->name()}' processor\n"; |
64
|
|
|
$input = $processor->process($input); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
echo "[|] Writing generated data to disk\n"; |
68
|
|
|
end($this->processors)->writeToDisk($input, $outfile); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.