MemoryHelper   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getRemembered() 0 4 1
A memorize() 0 4 1
A remember() 0 7 2
A forget() 0 4 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