Completed
Branch BETA-4.9-messages-queue-fixed (941081)
by
unknown
17:38 queued 10s
created

Base   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 58
rs 10
c 1
b 1
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A set_requested_version() 0 4 1
A get_model_version_info() 0 13 2
A is_subclass_of_one() 0 8 3
1
<?php
2
namespace EventEspresso\core\libraries\rest_api\controllers\model;
3
use EventEspresso\core\libraries\rest_api\controllers\Base as Controller_Base;
4
use EventEspresso\core\libraries\rest_api\Model_Version_Info;
5
6
if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) {
7
	exit( 'No direct script access allowed' );
8
}
9
10
/**
11
 *
12
 * Base
13
 *
14
 * Base controller which also has something to do with models
15
 *
16
 * @package			Event Espresso
17
 * @subpackage
18
 * @author				Mike Nelson
19
 *
20
 */
21
class Base extends Controller_Base {
22
	/**
23
	 * Holds reference to the model version info, which knows the requested version
24
	 * @var Model_Version_Info
25
	 */
26
	protected $_model_version_info;
27
28
/**
29
	 * Sets the version the user requested
30
	 * @param string $version eg '4.8'
31
	 */
32
	public function set_requested_version( $version ) {
33
		parent::set_requested_version( $version );
34
		$this->_model_version_info = new Model_Version_Info( $version );
35
	}
36
37
38
39
	/**
40
	 * Gets the object that should be used for getting any info from the models,
41
	 * because it's takes the requested and current core version into account
42
	 *
43
	 * @return \EventEspresso\core\libraries\rest_api\Model_Version_Info
44
	 * @throws \EE_Error
45
	 */
46
	public function get_model_version_info(){
47
		if( ! $this->_model_version_info ) {
48
			throw new \EE_Error(
49
				sprintf(
50
					__(
51
						'Cannot use model version info before setting the requested version in the controller',
52
						'event_espresso'
53
					)
54
				)
55
			);
56
		}
57
		return $this->_model_version_info;
58
	}
59
60
	/**
61
	 * Determines if $object is of one of the classes of $classes. Similar to
62
	 * in_array(), except this checks if $object is a subclass of the classnames provided
63
	 * in $classnames
64
	 *
65
	 * @param object $object
66
	 * @param array $classnames
67
	 * @return boolean
68
	 */
69
	public function is_subclass_of_one( $object, $classnames ) {
70
		foreach( $classnames as $classname ) {
71
			if( is_a( $object, $classname ) ) {
72
				return true;
73
			}
74
		}
75
		return false;
76
	}
77
78
}
79
80
// End of file Base.php