Type   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B __clone() 0 25 6
1
<?php
2
/**
3
 * Contains \jamesiarmes\PhpEws\Type.
4
 */
5
6
namespace jamesiarmes\PhpEws;
7
8
/**
9
 * Base class for Exchange Web Service Types.
10
 *
11
 * @package php-ews\Type
12
 */
13
abstract class Type
14
{
15
    /**
16
     * Clones any object properties on a type object when it is cloned. Allows
17
     * for a deep clone required when using object to represent data types when
18
     * making a SOAP call.
19
     */
20
    public function __clone()
21
    {
22
        // Iterate over all properties on the current object.
23
        foreach (get_object_vars($this) as $property => $value) {
24
            // If the value of the property is an object then clone it.
25
            if (is_object($value)) {
26
                $this->$property = clone $value;
27
            } elseif (is_array($value)) {
28
                // The value is an array that may use objects as values. Iterate
29
                // over the array and clone any values that are objects into a
30
                // new array.
31
                // For some reason, if we try to set $this->$property to an
32
                // empty array then update it as we go it ends up being empty.
33
                // If we use a new array that we then set as the value of
34
                // $this->$property all is well.
35
                $new_value = array();
36
                foreach ($value as $index => $array_value) {
37
                    $new_value[$index] = (is_object($array_value) ? clone $array_value : $array_value);
38
                }
39
40
                // Set the property to the new array.
41
                $this->$property = $new_value;
42
            }
43
        }
44
    }
45
}
46