Completed
Push — master ( bc6754...ed64c2 )
by
unknown
07:19
created

Basis::import()   C

Complexity

Conditions 8
Paths 18

Size

Total Lines 30
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 8
eloc 11
c 1
b 0
f 1
nc 18
nop 1
dl 0
loc 30
rs 5.3846
1
<?php
2
/**
3
 * Includes Basic Class methods that are common used in other classes.
4
 */
5
6
namespace Classy;
7
8
/**
9
 * Class Basis.
10
 *
11
 * @package Classy
12
 */
13
class Basis {
14
15
	/**
16
	 * Imports data params into the class instance
17
	 *
18
	 * @param  object|array $data
19
	 * @return void
20
	 */
21
	protected function import( $data ) {
22
23
		if ( is_object( $data ) ) {
24
25
			$data = get_object_vars( $data );
0 ignored issues
show
Coding Style introduced by
Consider using a different name than the parameter $data. This often makes code more readable.
Loading history...
26
27
		}
28
29
		if ( is_array( $data ) ) {
30
31
			// In case if we import WP_User object.
32
			if ( isset( $data['data'] ) ) {
33
				$data = $data['data'];
0 ignored issues
show
Coding Style introduced by
Consider using a different name than the parameter $data. This often makes code more readable.
Loading history...
34
			}
35
36
			foreach ( $data as $key => $value ) {
37
38
				if ( ! empty( $key ) ) {
39
40
					$this->$key = $value;
41
42
				} else if ( ! empty( $key ) && ! method_exists( $this, $key ) ) {
43
44
					$this->$key = $value;
45
46
				}
47
			}
48
		}
49
50
	}
51
}
52