GenerateLocaleData   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 22
dl 0
loc 60
rs 10
c 1
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 13 1
A render() 0 34 1
A __construct() 0 4 1
1
<?php
2
3
namespace ICanBoogie\CLDR\Generator\Command;
4
5
use ICanBoogie\CLDR\Repository;
6
use Symfony\Component\Console\Attribute\AsCommand;
7
use Symfony\Component\Console\Command\Command;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Output\OutputInterface;
10
use Symfony\Component\VarExporter\VarExporter;
11
12
use function ICanBoogie\CLDR\Generator\indent;
13
14
#[AsCommand(self::GENERATED_FILE)]
15
final class GenerateLocaleData extends Command
16
{
17
    private const GENERATED_FILE = 'src/Core/LocaleData.php';
18
19
    public function __construct(
20
        private readonly Repository $repository
21
    ) {
22
        parent::__construct();
23
    }
24
25
    protected function execute(InputInterface $input, OutputInterface $output): int
26
    {
27
        $parent_locales = $this->repository->supplemental['parentLocales'];
28
        $available_locales = $this->repository->fetch('core/availableLocales', 'availableLocales/full');
29
30
        $contents = $this->render(
31
            available_locales: indent(VarExporter::export($available_locales), 2),
32
            parent_locales: indent(VarExporter::export($parent_locales), 2),
33
        );
34
35
        file_put_contents(self::GENERATED_FILE, $contents);
36
37
        return self::SUCCESS;
38
    }
39
40
    public function render(
41
        string $available_locales,
42
        string $parent_locales,
43
    ): string {
44
        $class = __CLASS__;
45
46
        return <<<PHP
47
        <?php
48
49
        /**
50
         * CODE GENERATED; DO NOT EDIT.
51
         *
52
         * {@see \\$class}
53
         */
54
55
        namespace ICanBoogie\CLDR\Core;
56
57
        /**
58
         * @internal
59
         * @codeCoverageIgnore
60
         */
61
        final class LocaleData
62
        {
63
            /**
64
             * @link https://github.com/unicode-org/cldr-json/blob/47.0.0/cldr-json/cldr-core/availableLocales.json
65
             */
66
            public const AVAILABLE_LOCALES =
67
        $available_locales;
68
69
            /**
70
             * @link https://github.com/unicode-org/cldr-json/blob/47.0.0/cldr-json/cldr-core/supplemental/parentLocales.json
71
             */
72
            public const PARENT_LOCALES =
73
        $parent_locales;
74
75
            private function __construct()
76
            {
77
            }
78
        }
79
80
        PHP;
81
    }
82
}
83