Completed
Push — symfony-console-application ( 3187e2...c3ee2a )
by Luis
10:39
created

Processor   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 61
rs 10
c 0
b 0
f 0
wmc 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A writeToDisk() 0 3 1
A isCompatibleWith() 0 3 1
A getProcessors() 0 7 1
B factory() 0 20 6
A isInitial() 0 3 1
1
<?php
2
/**
3
 * PHP version 7.1
4
 *
5
 * This source file is subject to the license that is bundled with this package in the file LICENSE.
6
 */
7
namespace PhUml\Processors;
8
9
10
abstract class Processor
11
{
12
    public const INITIAL_INPUT_TYPE = 'application/phuml-structure';
13
14
    /**
15
     * @throws \plProcessorNotFoundException
16
     */
17
    public static function factory($processor): Processor
18
    {
19
        $processor = ucfirst($processor);
20
        if ($processor === 'Dot') {
21
            return new DotProcessor();
22
        }
23
        if ($processor === 'Neato') {
24
            return new NeatoProcessor();
25
        }
26
        if ($processor === 'Graphviz') {
27
            return new GraphvizProcessor(true);
28
        }
29
        if ($processor === 'Statistics') {
30
            return new StatisticsProcessor();
31
        }
32
        $classname = "pl{$processor}Processor";
33
        if (!class_exists($classname)) {
34
            throw new plProcessorNotFoundException($processor);
0 ignored issues
show
Bug introduced by
The type PhUml\Processors\plProcessorNotFoundException was not found. Did you mean plProcessorNotFoundException? If so, make sure to prefix the type with \.
Loading history...
35
        }
36
        return new $classname();
37
    }
38
39
    public static function getProcessors(): array
40
    {
41
        return [
42
            'Graphviz',
43
            'Neato',
44
            'Dot',
45
            'Statistics',
46
        ];
47
    }
48
49
    public function writeToDisk(string $input, string $output): void
50
    {
51
        file_put_contents($output, $input);
52
    }
53
54
    public function isCompatibleWith(Processor $nextProcessor): bool
55
    {
56
        return $this->getOutputType() === $nextProcessor->getInputType();
57
    }
58
59
    public function isInitial(): bool
60
    {
61
        return self::INITIAL_INPUT_TYPE === $this->getInputType();
62
    }
63
64
    abstract public function name(): string;
65
66
    abstract public function getInputType(): string;
67
68
    abstract public function getOutputType(): string;
69
70
    abstract public function process($input);
71
}
72