Strings   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 7
c 0
b 0
f 0
lcom 0
cbo 2
dl 0
loc 45
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getFormattedString() 0 9 2
B getString() 0 21 5
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: uruba
5
 * Date: 2/15/2016
6
 * Time: 2:54 PM
7
 */
8
9
namespace FinanCalc\Utils {
10
11
    use FinanCalc\FinanCalc;
12
13
    /**
14
     * Class Strings
15
     * @package FinanCalc\Utils
16
     */
17
    class Strings
18
    {
19
        /**
20
         * @param string $identifier
21
         * @param string|null $locale
22
         * @return string
23
         */
24
        public static function getFormattedString($identifier, $locale)
25
        {
26
            $formatArgs = array_slice(func_get_args(), 2);
27
28
            $unformattedString = Strings::getString($identifier, $locale);
29
30
            return is_null($unformattedString) ?
31
                null : vsprintf($unformattedString, $formatArgs);
32
        }
33
34
        /**
35
         * @param string $identifier
36
         * @param string|null $locale
37
         * @return string
38
         * @throws \Exception
39
         */
40
        public static function getString($identifier, $locale = null)
41
        {
42
            if (is_null($locale)) {
43
                $locale = Config::getConfigField("locale");
44
            }
45
46
            $localePath = FinanCalc::getPath() . "/locale/$locale.php";
47
48
            if (!file_exists($localePath)) {
49
                return null;
50
            }
51
52
            /** @noinspection PhpIncludeInspection */
53
            $strings = include($localePath);
54
55
            if (!is_array($strings) || !array_key_exists($identifier, $strings)) {
56
                return null;
57
            }
58
59
            return $strings[$identifier];
60
        }
61
    }
62
}
63