| Total Complexity | 9 |
| Total Lines | 78 |
| Duplicated Lines | 0 % |
| Coverage | 91.67% |
| Changes | 0 | ||
| 1 | <?php |
||
| 15 | final class Image implements ExporterInterface |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * @var string |
||
| 19 | */ |
||
| 20 | private $executable = 'dot'; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @var string |
||
| 24 | */ |
||
| 25 | private $format = 'svg'; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Image constructor. |
||
| 29 | */ |
||
| 30 | 4 | public function __construct() |
|
| 34 | } |
||
| 35 | 4 | } |
|
| 36 | |||
| 37 | /** |
||
| 38 | * @throws Exception |
||
| 39 | */ |
||
| 40 | 1 | public function export(NodeInterface $node): string |
|
| 41 | { |
||
| 42 | 1 | if (!($tmp = tempnam(sys_get_temp_dir(), 'phptree-export-'))) { |
|
| 43 | return ''; |
||
| 44 | } |
||
| 45 | |||
| 46 | 1 | file_put_contents($tmp, (new Gv())->export($node)); |
|
| 47 | |||
| 48 | 1 | return (string) shell_exec($this->getConvertCommand($tmp)); |
|
| 49 | } |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Get the executable to use. |
||
| 53 | */ |
||
| 54 | 3 | public function getExecutable(): string |
|
| 55 | { |
||
| 56 | 3 | return $this->executable; |
|
| 57 | } |
||
| 58 | |||
| 59 | 2 | public function getFormat(): string |
|
| 60 | { |
||
| 61 | 2 | return $this->format; |
|
| 62 | } |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Change the executable to use. |
||
| 66 | * |
||
| 67 | * @return \loophp\phptree\Exporter\Image |
||
| 68 | */ |
||
| 69 | 1 | public function setExecutable(string $executable): self |
|
| 70 | { |
||
| 71 | 1 | $this->executable = $executable; |
|
| 72 | |||
| 73 | 1 | return $this; |
|
| 74 | } |
||
| 75 | |||
| 76 | /** |
||
| 77 | * @return \loophp\phptree\Exporter\Image |
||
| 78 | */ |
||
| 79 | 1 | public function setFormat(string $format): self |
|
| 80 | { |
||
| 81 | 1 | $this->format = $format; |
|
| 82 | |||
| 83 | 1 | return $this; |
|
| 84 | } |
||
| 85 | |||
| 86 | 1 | private function getConvertCommand(string $path): string |
|
| 93 | ); |
||
| 94 | } |
||
| 95 | } |
||
| 96 |