Code Duplication    Length = 39-50 lines in 2 locations

src/Metadata/MethodMetadata.php 1 location

@@ 29-67 (lines=39) @@
26
 *
27
 * @author Johannes M. Schmitt <[email protected]>
28
 */
29
class MethodMetadata implements \Serializable
30
{
31
    public $class;
32
    public $name;
33
    public $reflection;
34
35
    public function __construct($class, $name)
36
    {
37
        $this->class = $class;
38
        $this->name = $name;
39
40
        $this->reflection = new \ReflectionMethod($class, $name);
41
        $this->reflection->setAccessible(true);
42
    }
43
44
    /**
45
     * @param object $obj
46
     * @param array  $args
47
     *
48
     * @return mixed
49
     */
50
    public function invoke($obj, array $args = array())
51
    {
52
        return $this->reflection->invokeArgs($obj, $args);
53
    }
54
55
    public function serialize()
56
    {
57
        return serialize(array($this->class, $this->name));
58
    }
59
60
    public function unserialize($str)
61
    {
62
        list($this->class, $this->name) = unserialize($str);
63
64
        $this->reflection = new \ReflectionMethod($this->class, $this->name);
65
        $this->reflection->setAccessible(true);
66
    }
67
}
68

src/Metadata/PropertyMetadata.php 1 location

@@ 29-78 (lines=50) @@
26
 *
27
 * @author Johannes M. Schmitt <[email protected]>
28
 */
29
class PropertyMetadata implements \Serializable
30
{
31
    public $class;
32
    public $name;
33
    public $reflection;
34
35
    public function __construct($class, $name)
36
    {
37
        $this->class = $class;
38
        $this->name = $name;
39
40
        $this->reflection = new \ReflectionProperty($class, $name);
41
        $this->reflection->setAccessible(true);
42
    }
43
44
    /**
45
     * @param object $obj
46
     *
47
     * @return mixed
48
     */
49
    public function getValue($obj)
50
    {
51
        return $this->reflection->getValue($obj);
52
    }
53
54
    /**
55
     * @param object $obj
56
     * @param string $value
57
     */
58
    public function setValue($obj, $value)
59
    {
60
        $this->reflection->setValue($obj, $value);
61
    }
62
63
    public function serialize()
64
    {
65
        return serialize(array(
66
            $this->class,
67
            $this->name,
68
        ));
69
    }
70
71
    public function unserialize($str)
72
    {
73
        list($this->class, $this->name) = unserialize($str);
74
75
        $this->reflection = new \ReflectionProperty($this->class, $this->name);
76
        $this->reflection->setAccessible(true);
77
    }
78
}
79