Completed
Push — master ( ed64c2...186a7a )
by
unknown
8s
created

Basis::import()   B

Complexity

Conditions 8
Paths 18

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 1
Metric Value
cc 8
eloc 11
c 2
b 1
f 1
nc 18
nop 1
dl 0
loc 20
rs 7.7777
1
<?php
2
/**
3
 * Includes Basic Class methods that are common used in other classes.
4
 *
5
 * @package Classy
6
 */
7
8
namespace Classy;
9
10
/**
11
 * Class Basis.
12
 */
13
class Basis {
14
15
	/**
16
	 * Imports data params into the class instance.
17
	 *
18
	 * @param  object|array $data
19
	 *
20
	 * @return void
21
	 */
22
	protected function import( $data ) {
23
		if ( is_object( $data ) ) {
24
			$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...
25
		}
26
27
		if ( is_array( $data ) ) {
28
			// In case if we import WP_User object.
29
			if ( isset( $data['data'] ) ) {
30
				$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...
31
			}
32
33
			foreach ( $data as $key => $value ) {
34
				if ( ! empty( $key ) ) {
35
					$this->$key = $value;
36
				} else if ( ! empty( $key ) && ! method_exists( $this, $key ) ) {
37
					$this->$key = $value;
38
				}
39
			}
40
		}
41
	}
42
}
43