Completed
Push — master ( 49324f...8a5a61 )
by Andrii
12:44
created

Interpolator   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 6
c 1
b 0
f 1
lcom 0
cbo 1
dl 0
loc 26
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A interpolate() 0 12 4
A get() 0 10 2
1
<?php
2
3
namespace hidev\components;
4
5
use Yii;
6
7
class Interpolator
8
{
9
    public function interpolate(&$data)
10
    {
11
        if (is_array($data)) {
12
            foreach ($data as &$item) {
13
                $this->interpolate($item);
14
            }
15
        } elseif (is_string($data)) {
16
            $data = preg_replace_callback('/\{{ (.*?) }}/', function ($matches) {
17
                return $this->get($matches[1]);
18
            }, $data);
19
        }
20
    }
21
22
    public function get($name)
23
    {
24
        list($scope, $subname) = explode('.', $name, 2);
25
26
        if ($scope === 'params') {
27
            return Yii::$app->params[$subname];
28
        } else {
29
            return null;
30
        }
31
    }
32
}
33