Code Duplication    Length = 53-66 lines in 2 locations

Components/Struct.php 1 location

@@ 10-62 (lines=53) @@
7
8
namespace ShopwarePlugins\Connect\Components;
9
10
abstract class Struct
11
{
12
    public function __construct(array $values = [])
13
    {
14
        foreach ($values as $name => $value) {
15
            $this->$name = $value;
16
        }
17
    }
18
19
    public function __get($name)
20
    {
21
        throw new \OutOfRangeException("Unknown property \${$name} in " . get_class($this) . '.');
22
    }
23
24
    public function __set($name, $value)
25
    {
26
        throw new \OutOfRangeException("Unknown property \${$name} in " . get_class($this) . '.');
27
    }
28
29
    public function __unset($name)
30
    {
31
        throw new \OutOfRangeException("Unknown property \${$name} in " . get_class($this) . '.');
32
    }
33
34
    public function __clone()
35
    {
36
        foreach ($this as $property => $value) {
37
            if (is_object($value)) {
38
                $this->$property = clone $value;
39
            }
40
            if (is_array($value)) {
41
                $this->cloneArray($this->$property);
42
            }
43
        }
44
    }
45
46
    /**
47
     * Clone array
48
     *
49
     * @param array $array
50
     */
51
    private function cloneArray(array &$array)
52
    {
53
        foreach ($array as $key => $value) {
54
            if (is_object($value)) {
55
                $array[$key] = clone $value;
56
            }
57
            if (is_array($value)) {
58
                $this->cloneArray($array[$key]);
59
            }
60
        }
61
    }
62
}
63

Struct/BaseStruct.php 1 location

@@ 10-75 (lines=66) @@
7
8
namespace ShopwarePlugins\Connect\Struct;
9
10
abstract class BaseStruct
11
{
12
    public function __construct(array $values = [])
13
    {
14
        foreach ($values as $name => $value) {
15
            $this->$name = $value;
16
        }
17
    }
18
19
    public function __get($name)
20
    {
21
        throw new \OutOfRangeException("Unknown property \${$name} in " . get_class($this) . '.');
22
    }
23
24
    public function __set($name, $value)
25
    {
26
        throw new \OutOfRangeException("Unknown property \${$name} in " . get_class($this) . '.');
27
    }
28
29
    public function __unset($name)
30
    {
31
        throw new \OutOfRangeException("Unknown property \${$name} in " . get_class($this) . '.');
32
    }
33
34
    public function __clone()
35
    {
36
        foreach ($this as $property => $value) {
37
            if (is_object($value)) {
38
                $this->$property = clone $value;
39
            }
40
41
            if (is_array($value)) {
42
                $this->cloneArray($this->$property);
43
            }
44
        }
45
    }
46
47
    /**
48
     * Clone array
49
     *
50
     * @param array $array
51
     */
52
    private function cloneArray(array &$array)
53
    {
54
        foreach ($array as $key => $value) {
55
            if (is_object($value)) {
56
                $array[$key] = clone $value;
57
            }
58
59
            if (is_array($value)) {
60
                $this->cloneArray($array[$key]);
61
            }
62
        }
63
    }
64
65
    /**
66
     * Restores struct from a previously stored state array.
67
     *
68
     * @param array $state
69
     * @return static
70
     */
71
    public static function __set_state(array $state)
72
    {
73
        return new static($state);
74
    }
75
}
76