Completed
Pull Request — develop (#542)
by Mathias
09:01
created

EventArgs::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
c 0
b 0
f 0
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * YAWIK
4
 *
5
 * @filesource
6
 * @copyright (c) 2013 - 2016 Cross Solution (http://cross-solution.de)
7
 * @license   MIT
8
 */
9
10
/** EventArgs.php */
11
namespace Core\Repository\DoctrineMongoODM\Event;
12
13
class EventArgs extends \Doctrine\Common\EventArgs
14
{
15
    private $values;
16
    
17 7
    public function __construct(array $values = array())
18
    {
19 7
        $this->values = $values;
20 7
    }
21
    
22 3
    public function get($key)
23
    {
24 3
        if (!isset($this->values[$key])) {
25
            throw new \OutOfBoundsException('Invalid key "' . $key . '"');
26
        }
27 3
        return $this->values[$key];
28
    }
29
    
30
    public function set($key, $value)
31
    {
32
        $this->values[$key] = $value;
33
        return $this;
34
    }
35
    
36
    public function __get($name)
37
    {
38
        return $this->get($name);
39
    }
40
    
41
    public function __set($name, $value)
42
    {
43
        return $this->set($name, $value);
44
    }
45
    
46
    public function __call($method, $params)
47
    {
48
        $type   = substr($method, 0, 3);
49
        
50
        if ('get' == $type || 'set' == $type) {
51
            $filter = function ($match) {
52
                return '_' . strtolower($match[0]);
53
            };
54
            $key = lcfirst(substr($method, 3));
55
            $key = preg_replace_callback('~([A-Z])~', $filter, $key);
56
            
57
            return 'get' == $type ? $this->get($key) : $this->set($key, (isset($params[0]) ? $params[0] : null));
58
        }
59
        
60
        throw new \BadMethodCallException('Unknown method: ' . $method);
61
    }
62
}
63