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

EventArgs   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Test Coverage

Coverage 26.09%

Importance

Changes 0
Metric Value
wmc 11
eloc 18
dl 0
loc 48
ccs 6
cts 23
cp 0.2609
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __get() 0 3 1
A get() 0 6 2
A __construct() 0 3 1
A __set() 0 3 1
A set() 0 4 1
A __call() 0 15 5
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