DataType   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0
Metric Value
wmc 6
lcom 0
cbo 0
dl 0
loc 34
rs 10

1 Method

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