Passed
Branch development-2.0 (2bf301)
by Jonathan
05:03
created

ArrayUtils   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 1
eloc 20
dl 0
loc 35
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A varExportToFile() 0 25 1
1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * ReportingCloud PHP Wrapper
6
 *
7
 * PHP wrapper for ReportingCloud Web API. Authored and supported by Text Control GmbH.
8
 *
9
 * @link      https://www.reporting.cloud to learn more about ReportingCloud
10
 * @link      https://github.com/TextControl/txtextcontrol-reportingcloud-php for the canonical source repository
11
 * @license   https://raw.githubusercontent.com/TextControl/txtextcontrol-reportingcloud-php/master/LICENSE.md
12
 * @copyright © 2019 Text Control GmbH
13
 */
14
15
namespace TxTextControl\ReportingCloud\Stdlib;
16
17
use Riimu\Kit\PHPEncoder\PHPEncoder;
18
19
/**
20
 * Class ArrayUtils
21
 *
22
 * @package TxTextControl\ReportingCloud
23
 * @author  Jonathan Maron (@JonathanMaron)
24
 */
25
class ArrayUtils extends AbstractStdlib
26
{
27
    /**
28
     * Write the array of passed data to a file as a PHP structure
29
     *
30
     * @param string $filename
31
     * @param array  $values
32
     *
33
     * @return int
34
     */
35 1
    public static function varExportToFile(string $filename, array $values): int
36
    {
37
        $options = [
38 1
            'array.indent'  => 4,
39
            'array.align'   => true,
40
            'array.omit'    => true,
41
            'array.short'   => true,
42
            'object.format' => 'export',
43
            'string.utf8'   => true,
44
            'whitespace'    => true,
45
        ];
46
47 1
        $encoder = new PHPEncoder($options);
48
49 1
        $data = '<?php';
50 1
        $data .= PHP_EOL;
51 1
        $data .= 'declare(strict_types=1);';
52 1
        $data .= PHP_EOL;
53 1
        $data .= PHP_EOL;
54 1
        $data .= 'return ';
55 1
        $data .= $encoder->encode($values);
56 1
        $data .= ';';
57 1
        $data .= PHP_EOL;
58
59 1
        return (int) file_put_contents($filename, $data);
60
    }
61
}
62