Passed
Pull Request — master (#400)
by Théo
03:00
created

ConfigurationExporter   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 19
dl 0
loc 31
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A export() 0 27 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the box project.
7
 *
8
 * (c) Kevin Herrera <[email protected]>
9
 *     Théo Fidry <[email protected]>
10
 *
11
 * This source file is subject to the MIT license that is bundled
12
 * with this source code in the file LICENSE.
13
 */
14
15
namespace KevinGH\Box\Console\Command;
16
17
use DateTimeImmutable;
18
use DateTimeZone;
19
use function function_exists;
20
use function get_loaded_extensions;
21
use function implode;
22
use KevinGH\Box\Configuration\Configuration;
23
use function KevinGH\Box\get_box_version;
24
use KevinGH\Box\NotInstantiable;
25
use function php_uname;
26
27
final class ConfigurationExporter
28
{
29
    use NotInstantiable;
30
31
    public static function export(Configuration $config): string
32
    {
33
        $date = (new DateTimeImmutable('now', new DateTimeZone('UTC')))->format(DATE_ATOM);
34
        $file = $config->getConfigurationFile() ?? 'No config file';
35
36
        $phpVersion = PHP_VERSION;
37
        $phpExtensions = implode(',', get_loaded_extensions());
38
        $os = function_exists('php_uname') ? PHP_OS.' / '.php_uname('r') : 'Unknown OS';
39
        $command = implode(' ', $GLOBALS['argv']);
40
        $boxVersion = get_box_version();
41
42
        $header = <<<EOF
43
//
44
// Processed content of the configuration file "$file" dumped for debugging purposes
45
//
46
// PHP Version: $phpVersion
47
// PHP extensions: $phpExtensions
48
// OS: $os
49
// Command: $command
50
// Box: $boxVersion
51
// Time: $date
52
//
53
54
55
EOF;
56
57
        return $header.$config->export();
58
    }
59
}
60