MemoryHelper::forget()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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