Conditions | 3 |
Paths | 4 |
Total Lines | 42 |
Code Lines | 30 |
Lines | 0 |
Ratio | 0 % |
Tests | 30 |
CRAP Score | 3.0003 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
24 | 4 | public static function varExportToFile(string $filename, array $values, string $generator = ''): int |
|
25 | { |
||
26 | 4 | $options = [ |
|
27 | 4 | 'array.indent' => 4, |
|
28 | 4 | 'array.align' => true, |
|
29 | 4 | 'array.omit' => true, |
|
30 | 4 | 'array.short' => true, |
|
31 | 4 | 'object.format' => 'export', |
|
32 | 4 | 'string.utf8' => true, |
|
33 | 4 | 'whitespace' => true, |
|
34 | 4 | ]; |
|
35 | |||
36 | 4 | $encoder = new PHPEncoder($options); |
|
37 | |||
38 | 4 | $format = '<?php'; |
|
39 | 4 | $format .= PHP_EOL; |
|
40 | 4 | $format .= 'declare(strict_types=1);'; |
|
41 | 4 | $format .= PHP_EOL . PHP_EOL; |
|
42 | 4 | $format .= '%s'; |
|
43 | 4 | $format .= 'return '; |
|
44 | 4 | $format .= '%s'; |
|
45 | 4 | $format .= ';'; |
|
46 | 4 | $format .= PHP_EOL; |
|
47 | |||
48 | 4 | if ('' === $generator) { |
|
49 | 2 | $prefix = ''; |
|
50 | } else { |
||
51 | 2 | $prefix = sprintf('// File generated by %s.', $generator); |
|
52 | 2 | $prefix .= PHP_EOL; |
|
53 | 2 | $prefix .= '// Do not edit.'; |
|
54 | 2 | $prefix .= PHP_EOL . PHP_EOL; |
|
55 | } |
||
56 | |||
57 | 4 | $buffer = sprintf($format, $prefix, $encoder->encode($values)); |
|
58 | |||
59 | 4 | $ret = file_put_contents($filename, $buffer); |
|
60 | |||
61 | 4 | if (!is_int($ret)) { |
|
|
|||
62 | $ret = 0; |
||
63 | } |
||
64 | |||
65 | 4 | return $ret; |
|
66 | } |
||
68 |