protected function generateGraphvizOutputFile(
        string $graphvizCode,
        string $targetFile,
        array $graphvizOptions = []
    ): GraphvizWriter
    {
        $graphvizOptions = array_replace_recursive(
            [
                'targetType'            => 'png'
            ],
            $graphvizOptions
        );
        $tmpFile = $targetFile.'.tmp';

        $this->removeFile($targetFile)
            ->removeFile($tmpFile);

        $this->writeFile($graphvizCode, $tmpFile);

        exec('dot -T'.$graphvizOptions['targetType'].' '.$tmpFile.' -o '.$targetFile, $output, $status);

        if ($status) {
            throw ExportException::create(
                'Couldn\'t generate Graphviz image. Exit Code: '.$status.' - Output: '.print_r($output, true)
            );
        }

        $this->removeFile($tmpFile);

        return $this;
    }