Total Complexity | 8 |
Total Lines | 55 |
Duplicated Lines | 0 % |
Coverage | 21.05% |
Changes | 0 |
1 | <?php |
||
6 | abstract class plProcessor |
||
7 | { |
||
8 | public const INITIAL_INPUT_TYPE = 'application/phuml-structure'; |
||
9 | |||
10 | /** |
||
11 | * @throws plProcessorNotFoundException |
||
12 | */ |
||
13 | public static function factory($processor): plProcessor |
||
14 | { |
||
15 | $processor = ucfirst($processor); |
||
16 | if ($processor === 'Dot') { |
||
17 | return new DotProcessor(); |
||
18 | } |
||
19 | if ($processor === 'Neato') { |
||
20 | return new NeatoProcessor(); |
||
21 | } |
||
22 | $classname = "pl{$processor}Processor"; |
||
23 | if (!class_exists($classname)) { |
||
24 | throw new plProcessorNotFoundException($processor); |
||
25 | } |
||
26 | return new $classname(); |
||
27 | } |
||
28 | |||
29 | public static function getProcessors(): array |
||
30 | { |
||
31 | return [ |
||
32 | 'Graphviz', |
||
33 | 'Neato', |
||
34 | 'Dot', |
||
35 | 'Statistics', |
||
36 | ]; |
||
37 | } |
||
38 | |||
39 | public function writeToDisk(string $input, string $output): void |
||
40 | { |
||
41 | file_put_contents($output, $input); |
||
42 | } |
||
43 | |||
44 | 12 | public function isCompatibleWith(plProcessor $nextProcessor): bool |
|
45 | { |
||
46 | 12 | return $this->getOutputType() === $nextProcessor->getInputType(); |
|
47 | } |
||
48 | |||
49 | 30 | public function isInitial(): bool |
|
52 | } |
||
53 | |||
54 | abstract public function name(): string; |
||
55 | |||
56 | abstract public function getInputType(): string; |
||
57 | |||
58 | abstract public function getOutputType(): string; |
||
59 | |||
60 | abstract public function process($input); |
||
61 | } |
||
62 |