MemoryHelper::remember()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 2
eloc 5
nc 1
nop 1
1
<?php
2
3
namespace JsonSpec\Behat\Helper;
4
5
class MemoryHelper
6
{
7
8
    protected $memory;
9
10
    public function __construct()
11
    {
12
        $this->forget();
13
    }
14
15
    public function getRemembered()
16
    {
17
        return $this->memory;
18
    }
19
20
    public function memorize($key, $value)
21
    {
22
        $this->memory[$key] = $value;
23
    }
24
25
    public function remember($value)
26
    {
27
        return preg_replace_callback('/\{\$([^\}]+?)}/', function ($matched) {
28
            return isset($this->memory[$matched[1]]) ?
29
                $this->memory[$matched[1]] : $matched[0];
30
        }, $value);
31
    }
32
33
    public function forget()
34
    {
35
        $this->memory = array();
36
    }
37
}
38