Text   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 31
rs 10
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A getText() 0 18 5
1
<?php
2
/**
3
 * This file is part of product_management
4
 * User: Sinan TURGUT <[email protected]>
5
 * Date: 24.06.2019
6
 * php version 7.2
7
 *
8
 * @category Assessment
9
 * @package  ProductManagement
10
 * @author   Sinan TURGUT <[email protected]>
11
 * @license  See LICENSE file
12
 * @link     https://dev.sinanturgut.com.tr
13
 */
14
15
namespace App\Utility;
16
17
/**
18
 * Class Text
19
 * @package App\Utility
20
 */
21
class Text
22
{
23
24
    /**
25
     * @var array
26
     */
27
    private static $_texts = [];
28
29
    /**
30
     * @param $key
31
     * @param array $data
32
     * @return mixed|string
33
     */
34
    public static function getText($key, array $data = [])
35
    {
36
37
        $stringsJson = json_decode(file_get_contents(VDIR.'/strings_'.APP_LANG.'.json'), true);
0 ignored issues
show
Bug introduced by
The constant App\Utility\APP_LANG was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
38
39
        if (empty(self::$_texts)) {
40
            $texts=$stringsJson['TEXTS'];
41
            self::$_texts = is_array($texts) ? $texts : [];
42
        }
43
        if (array_key_exists($key, self::$_texts)) {
44
            $text = self::$_texts[$key];
45
46
            foreach ($data as $search => $replace) {
47
                $text = str_replace($search, $replace, $text);
48
            }
49
            return $text;
50
        }
51
        return "";
52
    }
53
54
}
55
56