Code Duplication    Length = 20-20 lines in 2 locations

src/Builder.php 2 locations

@@ 30-49 (lines=20) @@
27
     *
28
     * @return array
29
     **/
30
    public static function addNames($codes)
31
    {
32
        // Read and decode JSON
33
        $json_data = json_decode(file_get_contents(__DIR__.'/languages.json'), true);
34
35
        $array = [];
36
37
        // Generate an array with $code as key and $code language as value
38
        foreach ($codes as $code) {
39
            $lang_name = 'Unknoun';
40
            foreach ($json_data as $lang_data) {
41
                if ($lang_data['code'] == $code) {
42
                    $lang_name = $lang_data['name'];
43
                }
44
            }
45
            $array[$code] = $lang_name;
46
        }
47
48
        return $array;
49
    }
50
51
    /**
52
     * Add names to an array of language codes as [$language => $code].
@@ 58-77 (lines=20) @@
55
     *
56
     * @return array
57
     **/
58
    public static function addCodes($langs)
59
    {
60
        // Read and decode JSON
61
        $json_data = json_decode(file_get_contents(__DIR__.'/languages.json'), true);
62
63
        $array = [];
64
65
        // Generate an array with $lang as key and $lang code as value
66
        foreach ($langs as $lang) {
67
            $code = 'unk';
68
            foreach ($json_data as $lang_data) {
69
                if ($lang_data['name'] == $lang) {
70
                    $code = $lang_data['code'];
71
                }
72
            }
73
            $array[$lang] = $code;
74
        }
75
76
        return $array;
77
    }
78
79
    /**
80
     * Returns the url to set up language and return back.