Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
CertificateHelper
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
2 / 2
7
100.00% covered (success)
100.00%
1 / 1
 saveFile
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 arrayToIni
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
5
1<?php
2
3declare(strict_types=1);
4/**
5 * SPDX-FileCopyrightText: 2025 LibreCode coop and contributors
6 * SPDX-License-Identifier: AGPL-3.0-or-later
7 */
8
9namespace OCA\Libresign\Handler\CertificateEngine;
10
11use OCA\Libresign\Exception\LibresignException;
12
13class CertificateHelper {
14    public static function saveFile(string $filename, string $content): void {
15        $success = file_put_contents($filename, $content);
16        if ($success === false) {
17            throw new LibresignException('Failure to save file. Check permission: ' . $filename);
18        }
19    }
20
21    public static function arrayToIni(array $config) {
22        $fileContent = '';
23        foreach ($config as $i => $v) {
24            if (is_array($v)) {
25                $fileContent .= "\n[$i]\n" . self::arrayToIni($v);
26            } else {
27                if (is_bool($v)) {
28                    $v = (int)$v;
29                }
30                $fileContent .= "$i = " . (str_contains((string)$v, "\n") ? '"' . $v . '"' : $v) . "\n";
31            }
32        }
33        return ltrim($fileContent, "\n");
34    }
35}